Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - WebMaka

Pages: [1]
1
OLEDs / NHD Slim OLED Character Display Driver for STM32
« on: March 24, 2019, 03:27:03 PM »
Thanks to some help from Saurabh Baxi at Newhaven, I was able to create a fully functional Arduino library for the slim OLED character display line. It works beautifully and only needs two lines from the Arduino to the display.

My current project has moved from "doable on an 8-bit MCU" to "needing more program space" to "an 8-bit MCU with enough flash memory costs more than a 32-bit ARM Cortex M0 with more than enough flash." And along with it, I need to drive a Newhaven slim OLED character display.

So I ported my library to STM32/HAL, and here's the first version if anyone else wants to have a go at it. Again, only two lines are required from the MCU and they don't need to be SPI - the driver bit-bangs SPI well enough that the display I'm using (NHD-0420CW) fired right up on the first try.

To use, select two pins and edit four lines in the header file to define the lines. The driver will automatically configure the pins for its use as part of its init process. Also, an include in the header will need to be edited as well.

The code tested successfully on a Nucleo-F070R dev board (STM32F070R), but thanks to using the HAL it should work on pretty much any STM32 MCU. The code was ported in Atollic TrueSTUDIO 9.3 - minimal changes may be required if using another IDE.

Here goes:

newhaven_slim_oled.h:

Code: [Select]
/*
 * Newhaven Display Slim OLED Driver
 * ---------------------------------
 *
 * Base SPI Code by Saurabh Baxi, Applications Engineer at Newhaven Display
 *   International, Inc.
 * Modifications and extensions by Tom Honaker.
 *
 *
 *
 * This is a comprehensive driver for running Newhaven's slim OLED character
 * displays from just about any STM32 MCU with enough free pins to connect to
 * one. The interface being used is SPI, but it's bit-banged on any two pins
 * so there's no requirement to use hardware SPI support.
 *
 * Check the datasheet for your display to wire it to the MCU in SPI mode.
 *
 * In order to save on precious memory, the library uses very little global
 * RAM. Variables are mainly declared inside functions so memory use is far
 * more local than global.
 *
 * The driver was designed and tested against a Newhaven NHD-0420CW-AB3 slim
 * OLED display module connected to a Nucleo-F070RB. The library should work
 * with few changes with any Newhaven slim OLED module and any STM32 MCU,
 * although some unused functions might need to be cut if memory space is at
 * a premium.
 *
 *
 *
 * IMPORTANT NOTE ON STRINGS/CHARS
 *
 * C/C++ strings end in nulls (0x00), but to a LCD or OLED display, character
 * code 0x00 is an actual character. When sending text to the display, remember
 * to NOT send a 0x00 unless displaying character #0 is the desired result!
 *
 *
 *
 * Software License Agreement (BSD License)
 *
 * Copyright (c) 2015-2017 by Newhaven Display International, Inc.
 * Copyright (c) 2017-2019 by Tom Honaker.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the copyright holders nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */



#ifndef NHD_OLED_DRIVER_H
#define NHD_OLED_DRIVER_H


#include <stdint.h>



// NOTE: Replace this line with the root HAL header for your specific MCU.
#include "stm32f0xx_hal.h"



// Pin Designations
//
// NOTE: EDIT THESE TO SUIT YOUR NEEDS. These pins don't have to be connected
// to an actual SPI module, and in fact it's probably best if they're not.
// The library will bit-bang SPI to the display, and thus doesn't need SPI
// hardware on the MCU.

// Data pin number     __________ - Change this as required.
#define OLED_MOSI_Pin  GPIO_PIN_8

// Data port                _____ - Change this as required.
#define OLED_MOSI_GPIO_Port GPIOB

// Clock pin number    __________ - Change this as required.
#define OLED_CLK_Pin   GPIO_PIN_9

// Clock port               _____ - Change this as required.
#define OLED_CLK_GPIO_Port  GPIOB



void NHD_OLED_begin(uint8_t rows, uint8_t columns);
void NHD_OLED_sendCommand(uint8_t command);
void NHD_OLED_sendData(uint8_t data);
void NHD_OLED_setupDisplaySize(uint8_t rows, uint8_t columns);
void NHD_OLED_setupPins();
void NHD_OLED_setupInit();
void NHD_OLED_displayControl(uint8_t display, uint8_t cursor, uint8_t block);
void NHD_OLED_displayOn();
void NHD_OLED_displayOff();
void NHD_OLED_textClear();
void NHD_OLED_cursorHome();
void NHD_OLED_cursorMoveToRow(uint8_t rowNumber);
void NHD_OLED_textClearRow(uint8_t rowNumber);
void NHD_OLED_shift(uint8_t dc, uint8_t rl);
void NHD_OLED_cursorPos(uint8_t row, uint8_t column);
void NHD_OLED_print_len(char *text, uint8_t len);
void NHD_OLED_print_char(char text);
void NHD_OLED_print_len_pos(char *text, uint8_t len, uint8_t r, uint8_t c);
void NHD_OLED_print_pos(char text, uint8_t r, uint8_t c);
void NHD_OLED_textPrintCentered(char *text, uint8_t length, uint8_t row);
void NHD_OLED_textPrintRightJustified(char *text, uint8_t length, uint8_t row);
void NHD_OLED_textSweep(char *text, uint8_t length, uint8_t row, char leftSweepChar, char rightSweepChar, uint8_t timeDelay);


// Display Geometry
uint8_t OLED_DISP_ROWS;
uint8_t OLED_DISP_COLUMNS;


// SPI Bit-Bang - This procedure shouldn't be called directly.
void NHD_OLED_SPIBitBang(uint8_t data, uint8_t isCommand);


#endif



/*
 * End of file!
 */


(Continued...)

2
OLEDs / NHD-0420CW-AB3, SPI, Arduino Mega
« on: September 30, 2017, 07:05:11 PM »
Greetings!

I just picked up a NHD-0420CW-AB3 20x4 OLED display for a project that involves using the display with an Arduino Mega 2560. However, in my initial testing I've run into some problems and thus far haven't gotten the display to function. I don't know if it's a wiring fault I'm just not seeing, or a software issue, or a bad display, or a combination thereof.

First, the wiring configuration, in "display pin > Mega pin" format:

1 > GND
2 > 5VDC
3 > 5VDC
4-6 > GND
7 > 52 (SCK)
8 > 51 (MOSI)
9 > 50 (MISO)
10-14 > GND
15 > 48 (RESET)
16 > 49 (CS)
17-20 > GND

Have I missed something somewhere that I'm just plain overlooking?

Second, I've tried the sample code Newhaven has posted to its Github repository but found it immediately clashed with other devices on the SPI bus because the sample code bit-bangs its way through SPI instead of using the Mega's actual hardware SPI interface and Arduino's built-in SPI library, so I suspect that sample code will not be helpful in my application as I have to have compatibility with the SPI library for other devices on the bus in use to function. Is there a working snippet of code that does play well with the integrated SPI (and with other devices on the bus) and Arduino library?

Third, I noticed that the corner of the display became warm to the touch under the ribbon cable on the right side. I did note that there were concerns about this form back in 2015 but I thought those were addressed by connecting pins 2 and 3 to 5VDC when using a 5VDC source.

Any insight anyone can provide would be greatly appreciated!


EDITED TO ADD:

I removed the Arduino from the project it's being used in (which was no small feat - I'm using 46 I/O lines, I2C, and SPI on it through a custom-made shield board) and uploaded only the sample library and basic "show some text" sample code from the Github repo, and still not getting anything from the display. It doesn't appear to power up at all. Beginning to think I got a bad one.

Pages: [1]