Sunspot Home

STM32 Index Page

Using the generic board (with the yellow jumpers) with code written for the Maple Mini

The generic board was tested with code from here - with thanks to Ray Burnette

A Nokia 5110 GLCD displays the output of a BMP180 pressure and temperature sensor.
(All of my eBay Chinese Nokia boards were not securely fastened to their circuit board.
If you press the edges the contrast can change to black - then fade randomly
.
I squeezed my board and LCD together while soldering the 4 lugs
- then changed the contrast setting to get a good display - see the code - it is now very stable )

Wiring the display, barometer and i2c lines -

Maple Mini Nokia 5110 Generic board *
PIN_SCE 31 CE (Active High) pin 2 PB12
PIN_RESET 30 Reset (Active Lo) pin 1 PB13
PIN_DC 29 Data==1 Command==0 pin 3 PB14
PIN_SDIN 28 MOSI/DIN pin 4 PB15
PIN_SCLK 27 CLK/clock pin 5 PA8

Maple Mini Function Generic board *
16 SCL PB7
15 SDA PB6
25 RXD (connect to TXD on USB-RS232 board) PA10
26 TXD (connect to RXD on USB-RS232 board) PA9
32 Button 2 (not the reset button) PB8

* the P may not be shown on the board lables but is needed in the code

A full list of which pins connect to the Maple Mini board pins is here

Notes (with thanks to help from Ray Burnette)
I placed all these files from the zip into a single folder -
GLCD5110_BMP085.ino
BMP085.h
BMP085.cpp
I2Cdev.cpp
ScrnFuncts.ino
Licenses.h

The main code is GLCD5110_BMP085.ino which incorporates any other .ino file in the same folder without calling for it (new to me!)
Because the supporting .h and .cpp files are in the same folder they do not need to be in the libraries folder. This means we can use modified versions for these files without confusing the other programs calling on the library.

#include <Wire.h> - means use the legacy version in the library.
#include "BMP085.h" - means use the modified file in the same folder as the main .ino

These lines are equivalent
#define PIN_SCE PB12 // CE (Active High) // pin 2
#define PIN_SCE 31 // CE (Active High) // pin 2

31 is the Maple Mini pin number and can be left in the program even if the board is generic.
The IDE inserted into the Arduino IDE is really designed for the Maple Mini and converts 31 to PB12.

My code stopped running originally at isButtonPressed - I guess this must be predefined in the IDE.

BOARD_LED_PIN must also be in the IDE so I inserted the pin PC13 for the generic board LED.

The modified code GLCD5110_BMP085.ino that runs on my generic board is -

/*
This implementation specific to Maple Mini and used with a NOKIA 5110 Craphic LCD
Placed in the Public Domain by author: m. ray burnette: http://hackster.io/RayBurne
Wikipedia: highest 1085.7hPa lowest non-tornadic 870hPa Delta == 215.7 hPa
Compiled using Arduino 1.6.0rc1
Sketch uses 19,212 bytes (17%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,800 bytes of dynamic memory.
*/

#include <Streaming.h> // http://arduiniana.org/libraries/streaming/ Documents\Arduino\libraries\Streaming (legacy)
#include <Wire.h> // I2C \Documents\Arduino\hardware\STM32\STM32F1XX\libraries\Wire (legacy)
#include "BMP085.h" // #include "I2Cdev.h" is pulled in also

//next line generic - #define LED_PIN BOARD_LED_PIN // defined for LeafLabs Maple & Maple Mini ... Real Arduinos it's PIN 13
#define LED_PIN PC13 // defined for LeafLabs Maple & Maple Mini ... Real Arduinos it's PIN 13

#define DIAGS false // set to "true" to echo diagnostic to SerialUSB - renamed to Serial

/* Nokia GLCD SOFTWARE SPI (using Maple Mini hardware SPI 2 Pins)
//------MapleMini-----//-------Notes------------//---Nokia--- */
#define PIN_SCE PB12 // CE (Active High) // pin 2
#define PIN_RESET PB13 // Reset (Active Lo) // pin 1
#define PIN_DC PB14 // Data==1 Command==0 // pin 3
#define PIN_SDIN PB15 // MOSI/DIN // pin 4
#define PIN_SCLK PA8 // CLK/clock // pin 5

#define LCD_C LOW
#define LCD_D HIGH
#define LCD_X 84
#define LCD_Y 48

// global GLCD variables
byte nRow; // line count (0-5 for NOKIA LCD = 6 lines)
byte nColumn; // character count (0-11 for NOKIA LCD= 12 chars)
byte NOKIAcontrast = 0x99; // LCD initialization contrast values B0 thru BF <----------originally 0XBC
byte error, address = 77; // I2C scanner
const byte ContrastPin = 8; // D8 low activates the Contrast adjustment <- remove this line - from an old program
const int BAUD = 9600; // any standard serial value: 300 - 115200 (not used for SerialUSB)
int hPa10, Fah10; // used for Nokia LCD integer to character - faux decimal place
int localCorrect = 3380; // +/- hPa*100 to correct for local altitude: 100X delta: 3380== Briscoe Field, Ga
float temperature;
float pressure; // How many hPa in 1 mm Hg? The answer is 1.3332239
float inHg;
float mmhg_conversion = 3386.388140071641; // convert hPa to inches Hg
float altitude;
int32_t lastMicros;
bool blinkState = false;

// Various static Screen messages
char* BlankLine[] PROGMEM = {" "}; // Nokia 12 x 6 (84 * 48)
// Screen line.... 012345678901 == 12 characters out of 72 char screen == 6 lines
char* msg0[] PROGMEM = {"DEMO BMP180 (C)2014 by M. Burnette PUBLIC DOMAIN Ver 20141231"}; // 72 characters == full screen
char* msg1[] PROGMEM = {" Open Serial Connection @9600 BAUD and then Press AnyKey"};
char* msg2[] PROGMEM = {"Barometer OK"} ;
char* msg3[] PROGMEM = {"Barometer Failure Correct and try again. "} ;

// create barometer object
BMP085 barometer;

void setup(void)
{
pinMode(PC13, OUTPUT);
pinMode(BOARD_BUTTON_PIN, INPUT);
pinMode(ContrastPin, INPUT);
digitalWrite(ContrastPin, HIGH); // activate internal pullup resistor
if( DIAGS )
{
Serial.begin(BAUD); // Maple SerialUSB .begin() is void... reminder for Serial1, 2, 3
Serial << (F("(c) 2013 - 2014 by M. R. Burnette")) << endl;
Serial << (F("Version 0.20140126")) << endl;
}

// I2C Stuff
Wire.begin(); barometer.initialize();


// Nokia SPI stuff
LcdInitialise(); LcdClear();
LcdString(*msg0);
delay(2000);
LcdClear();
LcdString(*msg1);


// wait with display until user sends a keystroke
if (DIAGS) do {} while (Serial.available() == 0) ;
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (DIAGS) Serial.println(barometer.testConnection() ? "BMP085 connection successful" : "BMP085 connection failed");
if (DIAGS) { Serial.print("Local Pressure Correction Constant: ") ; if (DIAGS) Serial.println(localCorrect); }
LcdClear();
if(barometer.testConnection())
{
LcdString(*msg2);
} else {
LcdString(*msg3);
for( ;; ) {;} // Create an infinite loop (lock-up)
}
}

void loop(void)
{
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
delay(1000);
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
delay(1000);
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
delay(1000);
Serial.println("loop starting");
// request temperature
barometer.setControl(BMP085_MODE_TEMPERATURE);

// wait appropriate time for conversion (4.5ms delay)
lastMicros = micros();
while (micros() - lastMicros < barometer.getMeasureDelayMicroseconds());

// read calibrated temperature value in degrees Celsius
temperature = barometer.getTemperatureC();

// request pressure (3x oversampling mode, high detail, 23.5ms delay)
barometer.setControl(BMP085_MODE_PRESSURE_3);
while (micros() - lastMicros < barometer.getMeasureDelayMicroseconds());

// read calibrated pressure value in Pascals (Pa)
pressure = barometer.getPressure();
pressure += localCorrect;
// calculate absolute altitude in meters based on known pressure
// (may pass a second "sea level pressure" parameter here,
// otherwise uses the standard value of 101325 Pa)
// altitude = barometer.getAltitude(pressure);

// display measured values if appropriate
if (DIAGS)
{
Serial.print("Temp/Pres:\t");
Serial << _FLOAT((temperature * 9.0 / 5.0) + 32.0 , 1) << "F \t";
Serial << _FLOAT((pressure / 100.0) , 2) << " hPa\t";
Serial << _FLOAT((pressure / mmhg_conversion) , 2) << " inHg" << endl;
// Serial << (int (altitude * 6.28084)) << " Ft \r\n" ;
}

// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);

Serial.print(" just blinked");

// update GLCD
// nRow = 5; nColumn = 0; // last line of Nokia 5110 - some pixels below screen on generic board
nRow = 4; nColumn = 0; // last line of Nokia 5110
gotoXY(nColumn, nRow);
LcdString(*BlankLine);
gotoXY(nColumn, nRow);
LcdString("inHg= ");


// if (isButtonPressed()) // Expand the inHg display by 2 additional spaces
// {
// inHg = float ( pressure * 10.0 / mmhg_conversion) * 100.0 ;
// } else {
inHg = float ( pressure * 10.0 / mmhg_conversion) ;
// }
nDisplay(inHg);

nRow = nRow - 1;
gotoXY(nColumn, nRow);
LcdString(*BlankLine);
gotoXY(nColumn, nRow);
LcdString(" hPa= ");
hPa10 = pressure / 10;
nDisplay(hPa10);

nRow = nRow - 1;
gotoXY(nColumn, nRow);
LcdString(*BlankLine);
gotoXY(nColumn, nRow);
LcdString(" tC= ");
nDisplay(10 * temperature);

nRow = nRow - 1;
gotoXY(nColumn, nRow);
LcdString(*BlankLine);
gotoXY(nColumn, nRow);
LcdString(" tF= ");
Fah10 = 10 * ((temperature * 9.0 / 5.0) + 32.0);
nDisplay(Fah10);

delay(1000); // wait 1 second before repeating...
}

With #define DIAGS true serial output was seen on the Arduino IDE serial monitor on pins UART PA9 PA10 that were used to upload the program.

My backup of the files I used

Please email me if you want to swap notes

SUNSPOT HOME

STM32 Index Page