Hi, I'm making a project and I'm having some problems with the display.
I have a couple of temperature sensors and a GPS. The data recorded by these devices through Arduino must be shown on the display: two thermometers for the temperatures and strings to show the GPS coordenates (latitude, longitude, date, time).
When I test each device separately, the display works correctly and shows everything with no problem. But when i put all together the device goes crazy, the numbers doesn´t look right in the strings, the thermometers disappear and a red cross appears in their place and things like these. This is the code I'm using:
As I said, everything goes right when I test them separately but when I put all together it doesn't work.
Does anybody know why is this happening?
I have a couple of temperature sensors and a GPS. The data recorded by these devices through Arduino must be shown on the display: two thermometers for the temperatures and strings to show the GPS coordenates (latitude, longitude, date, time).
When I test each device separately, the display works correctly and shows everything with no problem. But when i put all together the device goes crazy, the numbers doesn´t look right in the strings, the thermometers disappear and a red cross appears in their place and things like these. This is the code I'm using:
Code:
#include <genieArduino.h> #include <SoftwareSerial.h> //GPS library #include <OneWire.h> //Temperature sensor's DS18B20 library float tempC; int tempPin = 2; int DS18S20_Pin = 2; OneWire ds(DS18S20_Pin); SoftwareSerial gpsSerial(10, 11); // TX, RX (RX not used) const int sentenceSize = 80; char sentence[sentenceSize]; void setup() { genieBegin (GENIE_SERIAL, 9600); gpsSerial.begin(9600); } void loop() { GPS(); temperature1(); temperature2(); } float GPS() { static int i = 0; if (gpsSerial.available()) { char ch = gpsSerial.read(); if (ch != '\n' && i < sentenceSize) { sentence[i] = ch; i++; } else { sentence[i] = '\0'; i = 0; displayGPS(); } } } float temperature1() { tempC = analogRead(tempPin); tempC = (5.0 * tempC * 100.0)/1024.0; genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x00, tempC); genieWriteObject(GENIE_OBJ_THERMOMETER, 0x00, tempC); delay(1000); } float temperature2() { float temperature = getTemp(); genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x01, temperature); genieWriteObject(GENIE_OBJ_THERMOMETER, 0x00, temperature); delay(1000); } float getTemp() { byte data[12]; byte addr[8]; ds.reset(); ds.select(addr); ds.write(0x44,1); byte present = ds.reset(); ds.select(addr); ds.write(0xBE); for (int i = 0; i < 9; i++) { data[i] = ds.read(); } ds.reset_search(); byte MSB = data[1]; byte LSB = data[0]; float tempRead = ((MSB << 8) | LSB); //using two's compliment float TemperatureSum = tempRead / 16; return TemperatureSum; } void displayGPS() { char field[20]; getField(field, 0); if (strcmp(field, "$GPRMC") == 0) { getField(field, 9); // Date genieWriteStr(0,field); getField(field, 1); // Time genieWriteStr(1,field); getField(field, 3); // Latitude genieWriteStr(2,field); getField(field, 4); // N/S genieWriteStr(3,field); getField(field, 5); // Longitude genieWriteStr(4,field); getField(field, 6); // E/W genieWriteStr(5,field); } } void getField(char* buffer, int index) { int sentencePos = 0; int fieldPos = 0; int commaCount = 0; while (sentencePos < sentenceSize) { if (sentence[sentencePos] == ',') { commaCount ++; sentencePos ++; } if (commaCount == index) { buffer[fieldPos] = sentence[sentencePos]; fieldPos ++; } sentencePos ++; } buffer[fieldPos] = '\0'; }
Does anybody know why is this happening?
Comment