test code for hdc1080 humidity sensor
Fork of Nucleo-F303K8-SSD1306_OLED by
Diff: main.cpp
- Revision:
- 1:90d213185462
- Parent:
- 0:fa185766e039
- Child:
- 2:dc3e84d595c3
diff -r fa185766e039 -r 90d213185462 main.cpp --- a/main.cpp Sat Mar 19 02:18:42 2016 +0000 +++ b/main.cpp Mon Mar 21 00:11:05 2016 +0000 @@ -1,23 +1,46 @@ -/* Example of Reading all the ADC pins available on the Nucleo_F303K8. - by Joseph Ellsworth CTO A2WH - Free for all but no warranty, no promises */ +/* Example of Reading all the ADC pins PIN and display ot OLED display using + Nucleo_F303K8 by Joseph Ellsworth CTO A2WH - Free for all but no warranty, no promises + Attempt to drive: + ebay part http://www.ebay.com/itm/152000005331?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT + 0-96-I2C-IIC-SPI-Serial-White-OLED-LCD-LED-Display-Module-128X64 + The Datasheet. https://www.adafruit.com/datasheets/SSD1306.pdf + + Unfortunately this part never turns on using the SSD1308 library. + Not sure why and don't have time to finish tracking it down at this + time. + + Using my I2C address scanner I found that it responds on Added 120 (x78) ,121 (x79) + and when the part was unsoldered nothing responded on 120 or 121. According to + to the page #19 (8.1.5) of the data sheet the I2C address should be 011110 + which seems to map correctly to dec=120 hex=79 so I think the chip is responsive + and the library must be sending incorrect commands. + + */ #include "mbed.h" +#include "SSD1308.h" -// Initialize a pins to perform analog input and digital output fucntions -AnalogIn aA7(PA_2); -AnalogIn aA6(PA_7); -AnalogIn aA5(PA_6); -AnalogIn aA4(PA_5); -AnalogIn aA3(PA_4); -AnalogIn aA2(PA_3); -AnalogIn aA1(PA_1); -AnalogIn aA0(PA_0); -AnalogIn aB0(PB_0); -AnalogIn aB1(PB_1); +//#include "mbed_logo.h" + + //Pin Defines for I2C Bus + #define D_SDA PB_7 // specific for Nucleo-F303K8 + #define D_SCL PB_6 // specific for Nucleo-F303K8 + I2C i2c(D_SDA, D_SCL); + + // Host PC Communication channels + Serial pc(USBTX, USBRX); // tx, rx + + // Instantiate OLED + //SSD1308 oled = SSD1308(i2c, SSD1308_SA0); + SSD1308 oled = SSD1308(i2c, SSD1308_SA1); + //SSD1308 oled = SSD1308(i2c, 120); + +AnalogIn pa0(PA_0); DigitalOut myled(LED1); const float voltMeterARef = 3.3; +char buff[100]; float readPrint(AnalogIn ain, char *label) { float tval = ain.read(); float volts = tval * voltMeterARef; @@ -25,28 +48,33 @@ unsigned short tvalu16 = ain.read_u16 (); printf("adc %s R=%3.3f V=%3.3f%% U16=%u\r\n",label, tval, volts, tvalu16); - + sprintf(buff, "V=%3.3f%",volts); + oled.printf(buff); return tval; } int main() { + pc.printf("OLED test start\r"); + oled.writeString(0, 0, "Hello World !"); + oled.printf("Hello World !"); + + oled.fillDisplay(0xAA); + oled.setDisplayOff(); + wait(1); + oled.setDisplayOn(); + oled.clearDisplay(); + oled.setDisplayInverse(); + wait(0.5); + oled.setDisplayNormal(); + //oled.writeBitmap((uint8_t*) mbed_logo); + pc.printf("OLED test done\r\n"); + + while(1) { myled = !myled; // toggle led - readPrint(aA7, "PA_7"); - readPrint(aA6, "PA_6"); - readPrint(aA5, "PA_5"); - readPrint(aA4, "PA_4"); - readPrint(aA3, "PA_3"); - readPrint(aA2, "PA_2"); - readPrint(aA1, "PA_1"); - readPrint(aA0, "PA_0"); - - readPrint(aB0, "PB_0"); - readPrint(aB1, "PB_1"); - printf("\r\n\r\n"); - wait(7.0); - + readPrint(pa0, "PA_0"); + wait(7.0); } }