Announcement

Collapse
No announcement yet.

Ebike Part1 Voltage Reader Coding issues

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

  • Ebike Part1 Voltage Reader Coding issues

    Hi guys,
    I am having issues with my Voltage Reader, I am a complete novice and have been trying to get my sketch up and running. My project is to create an Ebike Display consisting of only 2 Forms, a Battery and Speedo/Odometer form. The speedo is Part 2 and not currently being worked on.

    At present I have the below Hardware connected as part 1

    uLCD-220RD-AR 4D Systems Display
    Arduino Uno R3
    Sensor Shield V5
    4 x Button switches with 10k resistors (2 with be for switching between Forms and the other 2 will be for Part 2)
    2 x Voltage dividers
    2 x 6c Multistar 16 000 mah batteries

    Part 2
    Hall Sensor


    Code:
    // Title : Ebike Battery Monitor, 
    // Outline :     Part 1 Check the voltages of the 2x 6s 16 000 mah then display on main 4D systems Monitor.
    //                Part 2 Speedo and Odometer to be included in next stage
    // Feb 2016
    // w1r3d sketch
    
    #include <genieArduino.h>
    #include <Button.h>
    
    Genie genie;
    
    #define RESETLINE 4                          // Using an Arduino Adaptor Shield Version 2
    
    int voltLED1;                                // Voltage reading of Battery 1
    int voltLED2;                                // Voltage reading of Battery 2
    int voltLED3;                                // Combined reading from both Batteries
    int sensorpin=A5;                            // Voltage divider from Battery 1
    int sensorpin=A4;                            // Voltage divider from Battery 2
    
    Button button1 = Button(7);                    // Button1 used to switch to BatteryForm
    Button button2 = Button(6);                    // Button2 used to switch to HallSensorForm
    // To be included in Part 2 Speedo/Odometer        Button button3 = Button(5);                    // Button3 used within HallSensorForm as Start/Stop odometer
    // To be included in Part 2 Speedo/Odometer        Button button4 = Button(4);                    // Button4 used within HallSensorForm as Zero odometer
    
    
    
    //To be included in Part 2 Speedo/Odometer        int hall_pin = 8;                            // Hall Sensor Digital Pin 8
    
    void setup()
    {
        Serial.begin(115200)
        
        mySerial.begin(200000);                 // 4d systems display Serial0 @ 200000 (200K) Baud
        genie.Begin(mySerial);                     //Serial for uLCD Use Serial0 for talking to the Genie Library, and to the 4D Systems display
     
      
      pinMode(RESETLINE, OUTPUT);                  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
      digitalWrite(RESETLINE, 1);                  // Reset the Display via D4
      delay(100);
      digitalWrite(RESETLINE, 0);                  // unReset the Display via D4
    
      delay (3500);                             //let the display start up after the reset (This is important)
      
      genie.WriteStr(0, GENIE_VERSION);            //Write a string to the Display to show the version of the library used
      delay (100);
      genie.WriteStr(0,"Sketch has started");    //Write to Display showing that sketch has started
      
       
    }
    
    void loop()
        genie.DoEvents();                            //Form is selected before any readings are taken form either the Hall Sensor or the Voltage Sensors, 
      
          if(button1.isPressed()){
         genie.WriteObject(GENIE_OBJ_FORM,0x01,0);    //Switch to Battery Form
     }
         if(button2.isPressed()){
           genie.WriteObject(GENIE_OBJ_FORM,0x02,0);//Switch to HallSensor Form
     }
         else{
         genie.WriteObject(GENIE_OBJ_FORM,0x01,0);    //Default Form it the BatteryForm
     }
    
        genie.ReadObject(GENIE_OBJ_FORM,0x01);
         if (millis() >= waitPeriod)
    {
       voltLED1=((5.0*analogRead(sensorpin)*1000)/1023);
       genie.WriteObject(GENIE_OBJ_LED_DIGITS,0x00,voltLED1);      //write to Leddigits0 the value of voltLED1 
       
       voltLED2=((5.0*analogRead(sensorpin)*1000)/1023);
       genie.WriteObject(GENIE_OBJ_LED_DIGITS,0x01,voltLED2);      //write to Leddigits1 the value of voltLED2 
       
       voltLED1+voltLED2=voltLED3
       genie.WriteObject(GENIE_OBJ_LED_DIGITS,0x02)                    //write combined Voltge to voltLED3
     }
                                                                      
       waitPeriod = millis()+50;                                    // rerun this code to update LEDdigits0 in another 50ms time.
       
     }

  • #2
    Hello,

    Sorry for delay in reply. Are you still having problems?

    Doesnt seem like you are setting up your serial ports right...

    Code:
    Serial.begin(115200)
        
        mySerial.begin(200000);                 // 4d systems display Serial0 @ 200000 (200K) Baud
        genie.Begin(mySerial);                     //Serial for uLCD Use Serial0 for talking to the Genie Library, and to the 4D Systems display
    mySerial looks to be something like SoftwareSerial, but then you dont have any software Serial library installed/included.
    And if you were wanting to use Software Serial, then 200000 baud for SoftwareSerial is too fast. 115200 is the max that Software Serial can do, and even that can be too fast for Software Serial to handle, depending what else you are doing in your code.

    Reply back if you need more help

    Regards
    James

    Comment

    Working...
    X