Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

DIY data collection (with link to working code for Arduino and Bluetooth )

13»

Comments

  • I am trying to build a Arduino Uno data device for measuring RPM and pedal position so that we can better select individual gear ratios for a Hewland gearbox to suit different circuits.
    The Racechrono sees the HT-05 module as the OBD-II and says
    Bluetooth OBD-II Reader, Connecting...(waiting). Connected, 0.0kbits/s
    Connected, no data from the...
    The sketch I have tried was written by Guzu I have tried the sketch as written and in modified form with the additional features such as temperature etc turned off.
    I can see the pedal position move on the Serial Monitor as I turn the 5k pot.
    I have the external GPS connected and can see my location in Racechrono.
    The baud rate is set at 9600. Do I need to change the baud rate?
    The GPS is stationary as is the laptop and UNO.
  • @Hustler You have to make sure that the Arduino is transmitting at the same baudrate as the HC-05 is set.
    If the the Arduino is transmitting at 9600 baudrate (Serial.begin(9600)) the HC-05 has to be set at 9600. (the default baudrate of the HC-05 is 9600)
  • Hi Guzu,
    The Racechrono now sees the HT-05 module as the OBD-II and says
    Bluetooth OBD-II Reader, Connected 3.0kbit/s.This varies but is generally around 3.0kbit/s.
    The OBD-II Reader still says Waiting for Data.
    Below is the code I am using that was posted by Guzu some time back.
    I have added a SoftSerial to talk to the Freetronics BT Shield plugged into a UNO board and have recently altered the Serial.begin(9600) and Serial.println to reflect this.
    eg: SoftSerial BTserial(2,3) , BTserial.begin(9600) and BTserial.println to write to the HC-05. This has now connected the BT Shield to Racechrono.
    I have left in the Serial.begin(9600) and Serial.println as the Serial Monitor requires it to work.
    The sketch has optional RC2 and RC3 string formats that I have been working with which I suspect is where my problems are coming from???? The sketch verifies and uploads ok.
    I have turned off some of the other features such as temperature.
    I can see the external GPS but no data from the BT Shield to the OBD-II reader.
    I have a 5k pot connected to A0 Pin, Gnd and 5v and can see it on the Serial Monitor.
    Any comments or assistance would be greatly appreciated.

    // Sketch Start

    #include

    SoftwareSerial BTserial(2,3); // RX | TX on Pins 2 & 3 of the Freetronics BT Shield with default setting of 9600 BAUD rate

    int rpm = 0, gear = 0, brake = 0, acceleration = 0, sensorValue1 = 0, sensorValue2 = 0;
    unsigned long count = 0, lastmillis = 0;
    volatile int half_revolutions = 0;
    unsigned long debounceDelay = 200; // the debounce time;
    unsigned long lastDebounceTime = 0; // the last time the gear was changed


    void setup(){
    BTserial.begin(9600); // 9600 sets Rx and Tx to digital pins 2 and 3, these are set with jumpers on the Freetronics Shield
    Serial.begin(9600); // 9600
    attachInterrupt(0, rpm_fan, FALLING);
    pinMode(A0, INPUT); // acceleration connected to a 5k pot
    //pinMode(A1, INPUT); // not used
    //pinMode(9, INPUT); // RPM not used as yet
    //pinMode(11, INPUT); // not used

    }
    void loop(){

    if (digitalRead(11) == HIGH){
    if ((millis() - lastDebounceTime) > debounceDelay) {
    gear += 1;
    if (gear>6){
    gear=6;
    }
    lastDebounceTime = millis();
    }
    }
    if (digitalRead(12) == HIGH){
    if ((millis() - lastDebounceTime) > debounceDelay) {
    gear -= 1;
    if (gear<1){
    gear=1;
    }
    lastDebounceTime = millis();
    }
    }

    //TEMP reading turn off
    //int reading = analogRead(2); // converting that reading to voltage, for 3.3v arduino use 3.3
    //float voltage = reading * 5.0;
    //voltage /= 1024.0;
    //float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offsetto degrees ((voltage - 500mV) times 100)

    sensorValue1 = analogRead(A0);
    //sensorValue2 = analogRead(A1);
    acceleration = map(sensorValue1, 0, 1023, 0, 100); //maps the input value of 0-1023 to 0-100
    //brake = map(sensorValue2, 0, 1023, 0, 100); //maps the input value of 0-1023 to 0-100

    if (millis() - lastmillis >= 100){ //Update every one hundredth of a second.
    detachInterrupt(0);//Disable interrupt when calculating
    rpm = half_revolutions * 60; // Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use half_revolutions * 30.
    half_revolutions = 0; // Restart the RPM counter
    lastmillis = millis(); // Update lasmillis
    attachInterrupt(0, rpm_fan, FALLING); //enable interrupt

    String buffer = "RC3,," + String(count) + ",,,,,,," + rpm + "," + acceleration + ",,,,,,,,,,,,,,"; // RC3 format. Removed gears, brake, temperatureC.
    //RC3,[time],[count],[xacc],[yacc],[zacc],[gyrox],[gyroy],[gyroz],[rpm/d1],[d2],[a1],[a2],[a3],[a4],[a5],[a6],[a7],[a8],[a9],[a10],[a11],[a12],[a13],[a14],[a15]*checksum


    //String buffer = "RC2,," + String(count) + "," + rpm + "," + "," + "," + acceleration + "," + "," + "," + "," + ",,,,,,";//Removed gears, brake, temperatureC.
    String checksum = String (checkSum(buffer), HEX);
    String data = "$" + buffer + "*" + checksum;
    BTserial.println (data); //prints data sent to pins 2&3 of BT shield
    Serial.println (data); // prints to serial monitor shows $RC2,,#,0,,,0-100,,,,,,,,,,*checksum or $RC3,,#,,,,,,,0,0-100,,,,,,,,,,,,,,*checksum
    //
    if (count == 65535){
    count = 0;
    }
    else
    count+=1;
    }
    }

    char checkSum(String chars) {
    char check = 0;
    for (int c = 0; c < chars.length(); c++) {
    check = char(check ^ chars.charAt(c));
    }
    return check;
    }

    void rpm_fan(){
    half_revolutions++;
    }
    //Racechrono shows H5-05 Bluetooth OBD-ii reader Connected, 3.2 kbit/s and OBD-II reader waiting for data
  • @DrMotor I read your discussion, you are using JDY-30. You talked about problems with this module and lower speed. And there are any advantages, compared with hc05/06?
  • @Hustler Hi. So basicly, you can se the data on the serial monitor, but you cannot see it in RaceChrono?
  • Guys, I can only recommend to raise the BT baudrate! This will speedup the messages per second instantly!

    It could be easy, but sadly the HC-models differ a bit (Lineendchar and stuff).
    But I found a way around it, which does it quite well for me:
    https://gist.github.com/HerrRiebmann/a0fe2e360512e332c78b435bfe802fe7

    But be aware: The Softwareserial is limited.

    @sst78rus I´m using a HC-06 and it works fine since several years.
  • una consulta, en que canal se ponen las RPM en el codigo para que racechrono lo lea?
  • @sebaguaita119, you should look for "RPM" in the code:
    >>> #define RPM PB0 // optional: Pin for ignition "probe"
    PB0 is a pin on STM32/"Blue pill".
    (Arduino Nano also has PB0, but I have not tried it for RPM)

    ...and it is sent to Rachechrono on the phone via $RC3, UART and bluetooth
  • @DrMotor - Is RaceTemp 0.7.5 the latest version? I'm getting a number of errors like ('HardwareTimer' was not declared in this scope) and ('I2C_FAST_MODE' was not declared in this scope). These appear to be library issues but my programming knowledge is based on an engineering FORTRAN class in the last century. I understand the program flow but don't know how to debug the structural issues.
  • @jspicer

    Did you follow the instructions under point 2 (and 2c) in the code?
    2c.Restart Arduino GUI and select:
    * Tools --> Boards --> Boards manager --> search for and install "SAM Boards"
    * Tools --> Boards --> Generic STM32F103C
    * Tools --> Upload method: STM32duino_bootloader (if you upload via USB)
    * Tools --> Variant --> set it to 128 kB (or try 64)
    ...

    It compiles OK on my computer. I only had to re-install (or upgrade?) "SAM Boards" after upgrading to new Arduino version.
  • Issue solved. Here was the problem. STM32duino.com does not exist any longer so you can't download the boards package. Its been ported to github with a different board package. I used the STMCores by STMmicroelectronics board package and got compile errors as stated above. RaceTemp 0.7.5 was written using the STM32duino board package and libraries. You must acquire the board manager package from http://dan.drown.org/stm32duino/package_STM32duino_index.json which does still exist by inserting the URL into the Additional Boards Manager URL in the preferences. Then you can choose the STM32F1xx/GD32F1xx board package by stm32duino. Uninstall the STMCores.
  • @jspicer
    You probably don't need that http-link to STM32duino: Just search for "SAM Boards" (and install) in the Arduino IDE under menu Tools --> Boards --> Boards manager -->
  • @DrMotor , first of all - Thanx for this project, it's awesome :-) Even though I'm a noop using STM32 and as such it's inspiring and a project I'm working on for a group of Yamaha KT100 users, myself included.

    Second, I've hit the same bump as you mentioned regarding the JDY-30 (I've got JDY-31, which essentially should be the same). When I look at the data the STM32 is producing (USB data output below) the BT transmission is being corrupted at 128000 baud and 115200baud (pic iaw. DB link). When I lower the baud to 9600 the data transmitted is more complete (pic iaw. DB link), but still some data is being corrupted, hence RaceChrono does not see the GPS data (waiting for data ... and No fix to sattelites).

    My setup is iaw. @mmrizio sketch --> https://www.dropbox.com/s/8leguhzyx7pivhb/RaceTemp0.75b.pdf?dl=0 with only the NEO M8N GPS Module attached. I've used both a Samsung GT-I9000 and a Huawei Mate7 same result!

    I can only think of possible error's below:
    1) Maybe the JDY-31 is not being configured correctly!
    I've referenced the datasheet, however, as an example, when I use the AT+BAUD or AT+VERSION commands the module does not return a response!
    https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwi09rOHhNbkAhVQIVAKHWgND_cQFjAAegQIAhAC&amp;url=http://myosuploads3.banggood.com/products/20190129/20190129043725SKUA87502.pdf&amp;usg=AOvVaw1mS7CdaI0em59S3IRDBa-L

    2) does the STM32F103C8T6 provide 5V on A9 TX, A10 RX?
    If yes, then I would need to add 1K/2K pull down on the TX?

    3) Maybe it's JDY-30/31 firmware issue as you stated?
    Well, I've just ordered some HC06 and try those instead.

    Lastly, I can't upload compile/upload sketch via USB even though the STM32 is recognized as COM6 Maple Mini, however I can compile/upload via the STLink! And as shown below, I can monitor the STM32 via USB. Wierd!!
    Using USB to compile/upload a sketch the Arduino returns with the following:
    maple_loader v0.1
    Resetting to bootloader via DTR pulse
    Searching for DFU device [1EAF:0003]...
    dfu-util - (C) 2007-2008 by OpenMoko Inc.
    Couldn't find the DFU device: [1EAF:0003]

    Sincerely
    Niels
    Denmark


    PNG's with 128000baud and 9600baud.
    https://www.dropbox.com/sh/25psaadyt7m83a4/AADQNFt33Zixn6en_JTJiU5Ua?dl=0

    STM32F103C8T6 data output from Serial Monitor (USB):
    22:15:46.713 -> RaceTemp -- DIY input device for RaceChrono. 100Hz update
    22:15:46.713 -> Bluetooth at baudrate 115200 :-/
    22:15:46.713 -> Setup GNS
    22:15:47.019 -> Setup analog channel(s)
    22:15:47.019 -> Setup digital channels (ignition probe for RPM)
    22:15:47.019 -> Setup timer
    22:15:47.019 -> Setup complete :p)
    22:15:47.019 -> $RC3,,0,0.000,0.000,0.000,0.000,0.000,0.000,inf,,25.803,105.273,50.000,40.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000*4E
    22:15:47.053 -> $GNRMC,000000.000,V,00000.00000,S,00000.00000,W,0.0000,0.00,000000,0.0,E,A*33
    22:15:47.053 -> $GPGGA,000000.000,0000.00000,S,00000.00000,W,0,00,0.00,0.0,M,0.0,M,,*52
    22:15:47.053 -> $GNRMC,000000.000,V,00000.00000,S,00000.00000,W,0.0000,0.00,000000,0.0,E,A*33
    22:15:47.053 -> $GPGGA,000000.000,0000.00000,S,00000.00000,W,0,00,0.00,0.0,M,0.0,M,,*52
    22:15:47.053 -> $GNRMC,000000.000,V,00000.00000,S,00000.00000,W,0.0000,0.00,000000,0.0,E,A*33
    22:15:47.088 -> $GPGGA,000000.000,0000.00000,S,00000.00000,W,0,00,0.00,0.0,M,0.0,M,,*52
    22:15:47.088 -> $GNRMC,000000.000,V,00000.00000,S,00000.00000,W,0.0000,0.00,000000,0.0,E,A*33
    22:15:47.088 -> $GPGGA,000000.000,0000.00000,S,00000.00000,W,0,00,0.00,0.0,M,0.0,M,,*52
    22:15:47.122 -> $RC3,,1,0.000,0.000,0.000,0.000,0.000,0.000,inf,,25.933,38.803,50.000,40.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000*7F
    22:15:47.224 -> $RC3,,2,0.000,0.000,0.000,0.000,0.000,0.000,inf,,26.001,32.753,50.000,40.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000*77
    22:15:47.326 -> $RC3,,3,0.000,0.000,0.000,0.000,0.000,0.000,inf,,26.040,29.930,50.000,40.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000*72
    22:15:47.393 -> $GNRMC,201547.600,A,05515.43353,N,00918.06510,E,0.0000,0.00,150919,0.0,E,A*29
    22:15:47.393 -> $GPGGA,201547.600,5515.43353,N,00918.06510,E,0,00,30826.11,29.1,M,44.0,M,,*5F
Sign In or Register to comment.