Announcement

Collapse
No announcement yet.

Problem with display

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with display

    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:

    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' &amp;&amp; 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';
     
    }
    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?

  • #2


    the numbers doesn´t look right in the stringsYou mean like the wrong font? IF so are you using 'Run RAM' or 'Run Flash'? Your program may be so big it is time to use 'Run Flash', although the IDE should have suggested that, unless you are using very old IDE version

    a red cross appears
    A red cross generally appears when you send an 'out of range' value. Have the object indexes changed and you are still using the old ones?

    Is the display ultimately locking up, or just displaying rubbish?
    Mark

    Comment


    • #3


      I'm using 'Run Flash'. The numbers don't appear in the strings they are supposed to be: I have 4 strings and the numbers of the string0 appears in the string3, for example.

      The red crosses appears because the temperature sensor gives unreal values out of range when all is conected together.

      I have been reading and this problem could be due to the delays in the code, so it must be a code problem.

      Comment


      • #4


        Hi Jarcor

        Probably best for you to send in your WS4 project and your Arduino code so we can take a closer look.

        It does look like you are only writing to the display, and never reading anything back from the display such as button presses - correct?
        You don't have an Event Handler at all, but since you appear to not be reading anything back then this may be OK.

        Regards
        James

        Comment


        • #5


          Hi again

          Just looking a bit closer at your code, I see a few issues.
          You are trying to pass a Float to the display for temperatures. You cannot do this, you can only pass Int's. You need to pass it for example 12345 in order to display 123.45 on the display. You then adjust the widget on the display to tell it how many decimal places to expect. 2 in this case. So you pass it 12345 and it will display 123.45
          I suggest you have a look at this App Note: http://www.4dsystems.com.au/downloads/Application-Notes/4D-AN-P4015_ViSi-Genie_Displaying_Temperature_Values_from_an_Arduino_Host_REV1.1.pdf

          M
          ost of your functions you have declared as float also, even though you don't return anything. Some should be void. May not affect anything, but something to check.

          Also I would check out the 'Blink without delay' example that comes with the Arduino IDE, and slow down your gps(), temperature1() and temperature2() calls from your main loop, as really you dont need to be updating these every single scan of the Arduino... You are going flood something. Also remove the delay's from your functions as they stop the arduino in its tracks as they are blocking. Refer to Blink without delay.

          See if that helps, if not, please send your WS4 application and your current Arduino code.

          Thanks
          James

          Comment


          • #6


            I removed the delays instead of millis and I slowed down the temperature sensor in order to be updated each 3 seconds and everything it's working fine now.

            Thank you very much!!!

            Comment


            • #7
              I'm trying to make it a little bit harder. I have added a gyroscope (2 axis). The GPS is working right and the numbers appears in the strings but the temperature sensor is giving unreal values again.

              This is the code:

              Code:
              #include <genieArduino.h>  
              #include <SoftwareSerial.h>  //GPS library
              #include <TinkerKit.h>  //Gyroscope library
              
              int tempC;      
              int tempPin = 5;  
              
              SoftwareSerial gpsSerial(10, 11); // TX, RX (RX not used)
              const int sentenceSize = 80;
              char sentence[sentenceSize];
              
              
              int tempState0 = LOW;
              long previousMillis0 =0;
              long interval0 = 3000;
              
              int tempState1 = LOW;
              long previousMillis1 =0;
              long interval1 =3000;
              
              TKGyro gyro(I0, I1, TK_X4); //Gyroscope function
              
              
              void setup() 
              { 
                genieBegin (GENIE_SERIAL, 9600);  
                gpsSerial.begin(9600); 
              }
              
              
              void loop() 
              { 
                  
                static int i = 0;
                if (gpsSerial.available())
                {
                  char ch = gpsSerial.read();
                  if (ch != '\n' &amp;&amp; i < sentenceSize)
                  {
                    sentence[i] = ch;
                    i++;
                  }
                  else
                  {
                   sentence[i] = '\0';
                   i = 0;
                   displayGPS();
                  }
                }    
                  
                  unsigned long currentMillis0 = millis();
                  if (currentMillis0 - previousMillis0 > interval0){
                    previousMillis0 = currentMillis0;
                    if (tempState0 == LOW)
                    tempState0 = HIGH;
                    else
                    tempState0 = LOW;
                    
                    digitalWrite(tempPin, tempState0);
                  tempC = analogRead(tempPin);         
                  tempC = (5.0 * tempC * 100.0)/1024.0; 
                  genieWriteObject(GENIE_OBJ_THERMOMETER, 0x00, tempC);
                  genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x00, tempC); 
                  }
                  
                  
                  unsigned long currentMillis1 = millis();
                  if (currentMillis1 - previousMillis1 > interval1){
                    previousMillis1 = currentMillis1;
                    if (tempState1 == LOW)
                    tempState1 = HIGH;
                    Serial.print(gyro.readXAxisRate());    // print the x-axis anguar rate in the range of -/+1500 °/s
                    Serial.println(gyro.readYAxisRate());  // print the x-axis anguar rate in the range of -/+1500 °/s
                  }
                  else{
                    tempState1 = LOW; 
                  }
               
               }
              
              
              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);
                  
                  getField(field, 8); //Course over ground
                  genieWriteObject(GENIE_OBJ_USERIMAGES,0x00,*field);
                  
                }
                
                getField(field, 0);
                if (strcmp(field, "$GPVTG") == 0)
                {
                  getField(field, 7);  // speed km/h
                  genieWriteStr(6,field);
                  genieWriteObject(GENIE_OBJ_COOL_GAUGE,0x00,*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';
               
              }

              Comment


              • #8


                Hi Jarcor

                Can you explain a bit more about what it is actually doing? Its giving unreal values again? What is the widget/object you are sending the number to expecting? Has it been set up with a decimal place? If so, are you sending 10x the number to it (assuming the object is in the format xxx.x) ?

                Only thing I can see, but most likely isnt an issue, is:

                HTML Code:
                tempC = analogRead(tempPin);         
                tempC = (5.0 * tempC * 100.0)/1024.0; 
                genieWriteObject(GENIE_OBJ_THERMOMETER, 0x00, tempC);
                genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x00, tempC);
                Where tempC is an int, however the calculation is going to exceed the limits of an int. But the compiler may take that into account itself.
                You could of course change tempC to be a long, and then typedef it into the genieWriteObject function. Even that however may not be required.
                I think by having 5.0 instead of 5 and 100.0 and 1024.0 instead of 100 and 1024, is making the compiler calculate it has a float.

                Something to try anyway. But I would look at what you are sending (maybe do a print statement as a test so you know what you are calculating at that point) and then look at what the WS4 application is expecting, what the digits and decimal parameters you have set are.

                Send your WS4 code if in doubt.

                Regards
                James

                Comment


                • #9


                  The temperature sensor should be sending a value between 20-22ºC, and in the display the value, at first, is at 20-22 but suddenly it changes to 14, then it goes to 25 and so.
                  This issue started when I included the gyroscope part in the code:

                  HTML Code:
                  unsigned long currentMillis1 = millis();
                      if (currentMillis1 - previousMillis1 > interval1){
                        previousMillis1 = currentMillis1;
                        if (tempState1 == LOW)
                        tempState1 = HIGH;
                        Serial.print(gyro.readXAxisRate());    // print the x-axis anguar rate in the range of -/+1500 °/s
                        Serial.println(gyro.readYAxisRate());  // print the x-axis anguar rate in the range of -/+1500 °/s
                      }
                      else{
                        tempState1 = LOW; 
                      }
                  I have already changed tempC to a long and the problem persists. The led digits object has been set up with no decimals.

                  Comment


                  • #10


                    Spotted your problem.

                    You are using Serial.print, which is printing to Serial0, which is where the display is connected. So you are corrupting the data that is going to the display, else sending the display values it cannot understand.

                    I take it you are trying to print the values to the serial terminal. You cant do this if you have the display connected to Serial0.

                    Print the values to the display using the appropriate Write Object commands.

                    Regards
                    James

                    Comment

                    Working...
                    X