Arduino Micro and NHD27OLED display
i'm trying nhd oled display (specficially nhd-2.7-12864umy3) working arduino micro , having difficulties. know others have been able display working other arduino models. i'll right - here's schematic:
i have wired on breadboard (except switches, lm34, , voltage divider going a0), display won't turn on. i've checked appropriate voltages , looks good.
any ideas? i've checked , triple checked micro documentation , oled display documentation , can't see i'm missing on electrical side. i've tried leaving rst line on display open, tied +3.3v, , set shown in schematic. i've put 'scope on pins , appears should nice clean dc +3.3v on power pin , can see data on data pin.
for reference, here's code loaded on micro testing. i'm sure i've screwed here, too, don't think keep oled display turning on.
i have wired on breadboard (except switches, lm34, , voltage divider going a0), display won't turn on. i've checked appropriate voltages , looks good.
any ideas? i've checked , triple checked micro documentation , oled display documentation , can't see i'm missing on electrical side. i've tried leaving rst line on display open, tied +3.3v, , set shown in schematic. i've put 'scope on pins , appears should nice clean dc +3.3v on power pin , can see data on data pin.
for reference, here's code loaded on micro testing. i'm sure i've screwed here, too, don't think keep oled display turning on.
code: [select]
#include <spi.h>
#include <u8glib.h>
// sketch arduino micro based voltmeter , thermometer using lm34
// connected nhd-2.7-12864umy3 oled 128x64 display.
// setup display driver
// u8glib_nhd27oled_gr u8g(10, 9); // u8glib_nhd27oled_gr(cs, a0 [, reset])
// u8glib_nhd27oled_gr u8g(13, 11, 10, 9); // u8glib_nhd27oled_gr(sck, mosi, cs, a0 [, reset])
// u8glib_nhd27oled_2x_gr u8g(13, 11, 10, 9); // u8glib_nhd27oled_2x_gr(sck, mosi, cs, a0 [, reset])
// arduino micro serial1 pins different
// u8glib_nhd27oled_2x_gr u8g(15, 16, 17, 9); // u8glib_nhd27oled_gr(sck, mosi, cs, a0 [, reset])
u8glib_nhd27oled_2x_gr u8g(17, 9); // u8glib_nhd27oled_gr(cs, a0 [, reset])
int cnt = 0; // testing
// setcontrast() stuff
int contupstate = 0;
int contdnstate = 0;
int contrastvalue = 255; // start display @ maximum contrast
const int contrastmin = 50; // minimum contrast want use - 0 actual hw minimum
const int contrastmax = 255; // maximum contrast
const int contraststep = 5; // how change contrast each push of button
unsigned char contuppin = 4; // push button turn contrast up
unsigned char contdnpin = 5; // push button turn contrast down
// displayvoltage() stuff
const int vm_num_samples = 10; // number of readings take average out later
int vmsum = 0; // sum of samples taken
int vmsample_count = 0; // current sample number
unsigned char vmpin = a0; // use pin a0 input 12v after voltage divider - don't exceed 5v actual
float vmvoltage = 0.00; // calculated voltage
float vmout = 0.00; // voltage output
int voltwidth = 0; // width of voltage reading in pixels
int voltspace = 0;
// displaytemp() stuff
unsigned char temppin = a1; // use pin a1 input lm34
int tempwidth = 0; // width of temperature reading in pixels
int tempspace = 0;
void setup() {
serial1.begin(9600); // arduino micro uses serial1 hardware serial
// assign pins
pinmode(4, input_pullup); // push button turn contrast up
digitalwrite(4, high); // turn on internal pull-up resistor
pinmode(5, input_pullup); // push button turn contrast down
digitalwrite(5, high); // turn on internal pull-up resistor
pinmode(9, output); // data out oled display - spi2_si on nhd display
pinmode(10, output); // cs out display
// a0 - input displayvoltage()
// a1 - input displaytemp()
// testing stuff
u8g.begin();
u8g.setcontrast(255);
u8g.setcolorindex(1);
delay(5000);
u8g.setcolorindex(0);
delay(5000);
u8g.setcontrast(127);
u8g.setcolorindex(1);
delay(5000);
u8g.setcolorindex(0);
delay(5000);
u8g.setcontrast(255);
}
void displayvoltage() {
// take number of analog samples , add them up
while (vmsample_count < vm_num_samples) {
vmsum += analogread(vmpin); // read voltage , add previous readings
vmsample_count++; // increment counter
delay(10);
}
// calculate voltage
// use 5.0 5.0v adc reference voltage
// 5.015v calibrated reference voltage
vmvoltage = ((float)vmsum / (float)vm_num_samples * 5.015) / 1024.0;
// send voltage display
// voltage multiplied 11 when using voltage divider that
// divides 11. 11.132 calibrated voltage divide
// value
vmout = vmvoltage * 11.132;
voltwidth = u8g.getstrwidth("vmout"); // how wide voltage reading in pixels
voltspace = voltwidth + 5;
u8g.setfontpostop(); // set 0,0 @ upper left
u8g.setfont(u8g_font_9x15br); // set font - 9x15 bold
u8g.setprintpos(0, 30); // start in upper left corner
u8g.print(vmout); // print voltage
u8g.setfont(u8g_font_9x15r); // set font - 9x15 regular
u8g.setprintpos(voltspace, 30); // set position next line
u8g.print("v"); // print v next voltage reading
// reset counter variables
vmsample_count = 0;
vmsum = 0;
}
void displaytemp() {
int rawvoltage = analogread(temppin); // read volage lm34 - 1.000v = 100 deg f
float millivolts = (rawvoltage/1024.0) * 5000;
float degf = millivolts/10;
tempwidth = u8g.getstrwidth("degf"); // how wide temperature reading in pixels
tempspace = tempwidth + 5;
u8g.setfontpostop(); // set 0,0 @ upper left
u8g.setfont(u8g_font_9x15br); // set font
u8g.setprintpos(63, 30); // set print position reading
u8g.print(degf); // print temperature
u8g.setfont(u8g_font_9x15r); // set font
u8g.setprintpos(tempspace, 30); // set print position next line
u8g.print("f"); // print f next temp reading
delay(1000); // wait 1 sec between updates
}
void setcontrast() {
// read state of contrast buttons
contupstate = digitalread(contuppin);
contdnstate = digitalread(contdnpin);
// check if 1 of contrast buttons pressed.
// if is, button state low
if (contupstate == low) { // contrast button pushed
if (contrastvalue >= contrastmin) { // check make sure not way down already
contrastvalue == contrastvalue + contraststep; // adjust contrast 1 step
u8g.setcontrast(contrastvalue); // send new contrast value display
}
}
if (contdnstate == low) { // contrast down button pushed
if (contrastvalue <= contrastmax) { // check make sure not way already
contrastvalue == contrastvalue - contraststep; // adjust contrast down 1 step
u8g.setcontrast(contrastvalue); // send new contrast value display
}
}
}
// testing only
void draw() {
// graphic commands redraw complete screen should placed here
u8g.setfont(u8g_font_6x12r);
u8g.drawstr( 0, 15, "6x12r");
// u8g.setfont(u8g_font_6x12br);
// u8g.drawstr( 63, 15, "6x12br");
u8g.setfont(u8g_font_9x15r);
u8g.drawstr( 0, 30, "9x15r");
u8g.setfont(u8g_font_9x15br);
u8g.drawstr( 63, 30, "9x15br");
u8g.setfont(u8g_font_9x18r);
u8g.drawstr( 0, 50, "9x18r");
u8g.setfont(u8g_font_9x18br);
u8g.drawstr( 63, 50, "9x18br");
u8g.setfont(u8g_font_10x20r);
u8g.drawstr( 0, 63, "10x20r");
// u8g.setfont(u8g_font_10x20br);
// u8g.drawstr( 63, 63, "10x20br");
}
void loop() {
// picture loop
u8g.firstpage();
{
draw(); // testing only
}
while( u8g.nextpage() );
// rebuild picture after delay
delay(1000);
setcontrast(); // screen contrast adjustment via push buttons
//displayvoltage(); // display vehicle voltage
//displaytemp(); // display ambient temperature
}
anyone? ideas appreciated.
thanks!
thanks!
Arduino Forum > Using Arduino > Displays > Arduino Micro and NHD27OLED display
arduino
Comments
Post a Comment