[SOLVED] Sensebender Micro Baud Rate Issue.

  • I just brought up two Sensebender Micros. I was able to download the temp/Humidity sketch in both unites. In both cases when I opened the Serial Monitor the only baud rate that works is 230400 despite trying to set it in the Sketch and in Myconfig.h to 112500. When I open the Serial Monitor it appears to run through its startup just fine but then it looks like its baud rate get changed. After that it's never heard from again. I've gone through all the baud rates but nothing seem to match up. Anybody got any ideas? I've included the Serial Monitor output along with the Sketch.

    4 TSM:INIT
    4 TSF:WUR:MS=0
    22 TSF:SID:OK,ID=44
    24 TSM:FPAR
    96 TSF:MSG:SEND,44-44-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    1476 TSF:MSG:READ,25-25-44,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    1482 TSF:MSG:FPAR OK,ID=25,D=2
    2105 TSM:FPAR:OK
    2105 TSM:ID
    2107 TSM:ID:OK
    2109 TSM:UPL
    2113 TSF:MSG:SEND,44-44-25-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2189 TSF:MSG:READ,0-25-44,s=255,c=3,t=25,pt=1,l=1,sg=0:2
    2199 TSM:UPL:OK
    2199 TSM:READY:ID=44,PAR=25,DIS=2
    2207 TSF:MSG:SEND,44-44-25-0,s=255,c=4,t=0,pt=6,l=10,sg=0,ft=0,st=OK:FFFFFFFFFFFFFFFF0300
    2220 TSF:MSG:SEND,44-44-25-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2324 TSF:MSG:READ,0-25-44,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2334 TSF:MSG:SEND,44-44-25-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
    2344 TSF:MSG:SEND,44-44-25-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:25
    4358 TSF:MSG:SEND,44-44-25-0,s=255,c=3,t=11,pt=0,l=25,sg=0,ft=0,st=OK:Sensebender Micro #1 V1.0
    4372 TSF:MSG:SEND,44-44-25-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.4
    4450 !TSF:MSG:SEND,44-44-25-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=NACK:
    4460 TSF:MSG:SEND,44-44-25-0,s=2,c=0,t=7,pt=0,l=0,sg=0,ft=1,st=OK:
    4470 TSF:MSG:SEND,44-44-25-0,s=199,c=0,t=13,pt=0,l=0,sg=0,ft=0,st=OK:
    4478 MCO:REG:REQ
    4550 !TSF:MSG:SEND,44-44-25-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=NACK:2
    6561 TSF:MSG:SEND,44-44-25-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=OK:2
    6621 TSF:MSG:READ,0-25-44,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    6627 MCO:PIM:NODE REG=1
    6629 MCO:BGN:STP
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     * Version 1.0 - Thomas Bowman Mørch
     * Default sensor sketch for Sensebender Micro module
     * Act as a temperature / humidity sensor by default.
     * If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals
     * Battery voltage is as battery percentage (Internal message), and optionally as a sensor value (See defines below)
     * Version 1.3 - Thomas Bowman Mørch
     * Improved transmission logic, eliminating spurious transmissions (when temperatuere / humidity fluctuates 1 up and down between measurements) 
     * Added OTA boot mode, need to hold A1 low while applying power. (uses slightly more power as it's waiting for bootloader messages)
     * Version 1.4 - Thomas Bowman Mørch
     * Corrected division in the code deciding whether to transmit or not, that resulted in generating an integer. Now it's generating floats as expected.
     * Simplified detection for OTA bootloader, now detecting if MY_OTA_FIRMWARE_FEATURE is defined. If this is defined sensebender automaticly waits 300mS after each transmission
     * Moved Battery status messages, so they are transmitted together with normal sensor updates (but only every 60th minute)
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    // #define MY_BAUD_RATE 115200
    // Define a static node address, remove if you want auto address assignment
    #define MY_NODE_ID 44
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    // Enable to support OTA for this node (needs DualOptiBoot boot-loader to fully work)
    // Enabled repeater feature for this node
    // #define MY_REPEATER_FEATURE
    #include <SPI.h>
    #include <MySensors.h>
    #include <Wire.h>
    #include <SI7021.h>
    #include "drivers/SPIFlash/SPIFlash.cpp"
    #include <EEPROM.h>  
    #include <sha204_lib_return_codes.h>
    #include <sha204_library.h>
    #include <RunningAverage.h>
    //#include <avr/power.h>
    // Uncomment the line below, to transmit battery voltage as a normal sensor value
    #define BATT_SENSOR    199
    #define RELEASE "1.4"
    #define AVERAGES 2
    // Child sensor ID's
    #define CHILD_ID_TEMP  1
    #define CHILD_ID_HUM   2
    // How many milli seconds between each measurement
    #define MEASURE_INTERVAL 60000
    // How many milli seconds should we wait for OTA?
    #define OTA_WAIT_PERIOD 300
    // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller
    // When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes.
    // Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement
    // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with
    // TEMP_TRANSMIT_THRESHOLD for temperature threshold.
    // Pin definitions
    #define TEST_PIN       A0
    #define LED_PIN        A2
    #define ATSHA204_PIN   17 // A3
    const int sha204Pin = ATSHA204_PIN;
    atsha204Class sha204(sha204Pin);
    SI7021 humiditySensor;
    SPIFlash flash(8, 0x1F65);
    // Sensor messages
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    #ifdef BATT_SENSOR
    MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE);
    // Global settings
    int measureCount = 0;
    int sendBattery = 0;
    boolean isMetric = true;
    boolean highfreq = true;
    boolean transmission_occured = false;
    // Storage of old measurements
    float lastTemperature = -100;
    int lastHumidity = -100;
    long lastBattery = -100;
    RunningAverage raHum(AVERAGES);
     * Setup code 
    void setup() {
      pinMode(LED_PIN, OUTPUT);
      digitalWrite(LED_PIN, LOW);
      Serial.println("SensebenderMicro #2 V1.0.1");
      Serial.print(F("Sensebender Micro FW "));
      // First check if we should boot into test mode
      digitalWrite(TEST_PIN, HIGH); // Enable pullup
      if (!digitalRead(TEST_PIN)) testMode();
      // Make sure that ATSHA204 is not floating
      pinMode(ATSHA204_PIN, INPUT);
      digitalWrite(ATSHA204_PIN, HIGH);
      digitalWrite(LED_PIN, HIGH); 
      digitalWrite(LED_PIN, LOW);
      Serial.println(F(" - Online!"));
      isMetric = getControllerConfig().isMetric;
      Serial.print(F("isMetric: ")); Serial.println(isMetric);
      Serial.println("OTA FW update enabled");
    void presentation()  {
      sendSketchInfo("Sensebender Micro #1 V1.0.1", RELEASE);
    #ifdef BATT_SENSOR
      present(BATT_SENSOR, S_POWER);
     *  Main loop function
    void loop() {
      measureCount ++;
      sendBattery ++;
      bool forceTransmit = false;
      transmission_occured = false;
      if (measureCount >= FORCE_TRANSMIT_INTERVAL) { // force a transmission
        forceTransmit = true; 
        measureCount = 0;
    /*  if (sendBattery > 60) 
         sendBattLevel(forceTransmit); // Not needed to send battery info that often
         sendBattery = 0;
      if (transmission_occured) {
     * Sends temperature and humidity from Si7021 sensor
     * Parameters
     * - force : Forces transmission of a value (even if it's the same as previous measurement)
    void sendTempHumidityMeasurements(bool force)
      bool tx = force;
      si7021_env data = humiditySensor.getHumidityAndTemperature();
      float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0);
      float diffHum = abs(lastHumidity - raHum.getAverage());
      Serial.print(F("TempDiff :"));Serial.println(diffTemp);
      Serial.print(F("HumDiff  :"));Serial.println(diffHum); 
      if (isnan(diffHum)) tx = true; 
      if (diffTemp >= TEMP_TRANSMIT_THRESHOLD) tx = true;
      if (diffHum >= HUMI_TRANSMIT_THRESHOLD) tx = true;
      if (tx) {
        measureCount = 0;
        float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0;
        int humidity = data.humidityPercent;
        Serial.print("T: ");Serial.println(temperature);
        Serial.print("H: ");Serial.println(humidity);
        lastTemperature = temperature;
        lastHumidity = humidity;
        transmission_occured = true;
        if (sendBattery > 60) {
         sendBattLevel(true); // Not needed to send battery info that often
         sendBattery = 0;
     * Sends battery information (battery percentage)
     * Parameters
     * - force : Forces transmission of a value
    void sendBattLevel(bool force)
      if (force) lastBattery = -1;
      long vcc = readVcc();
      if (vcc != lastBattery) {
        lastBattery = vcc;
    #ifdef BATT_SENSOR
        float send_voltage = float(vcc)/1000.0f;
        // Calculate percentage
        vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at
        long percent = vcc / 14.0;
        transmission_occured = true;
     * Internal battery ADC measuring 
    long readVcc() {
      // Read 1.1V reference against AVcc
      // set the reference to Vcc and the measurement to the internal 1.1V reference
      #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
        ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
      #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
        ADMUX = _BV(MUX5) | _BV(MUX0);
      #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
        ADcdMUX = _BV(MUX3) | _BV(MUX2);
        ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
      delay(2); // Wait for Vref to settle
      ADCSRA |= _BV(ADSC); // Start conversion
      while (bit_is_set(ADCSRA,ADSC)); // measuring
      uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
      uint8_t high = ADCH; // unlocks both
      long result = (high<<8) | low;
      result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
      return result; // Vcc in millivolts
     * Verify all peripherals, and signal via the LED if any problems.
    void testMode()
      uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      uint8_t ret_code;
      byte tests = 0;
      digitalWrite(LED_PIN, HIGH); // Turn on LED.
      Serial.println(F(" - TestMode"));
      Serial.println(F("Testing peripherals!"));
      Serial.print(F("-> SI7021 : ")); 
      if (humiditySensor.begin()) 
        tests ++;
      Serial.print(F("-> Flash : "));
      if (flash.initialize())
        tests ++;
      Serial.print(F("-> SHA204 : "));
      ret_code = sha204.sha204c_wakeup(rx_buffer);
      if (ret_code != SHA204_SUCCESS)
        Serial.print(F("Failed to wake device. Response: ")); Serial.println(ret_code, HEX);
      if (ret_code == SHA204_SUCCESS)
        ret_code = sha204.getSerialNumber(rx_buffer);
        if (ret_code != SHA204_SUCCESS)
          Serial.print(F("Failed to obtain device serial number. Response: ")); Serial.println(ret_code, HEX);
          Serial.print(F("Ok (serial : "));
          for (int i=0; i<9; i++)
            if (rx_buffer[i] < 0x10)
              Serial.print('0'); // Because Serial.print does not 0-pad HEX
            Serial.print(rx_buffer[i], HEX);
          tests ++;
      Serial.println(F("Test finished"));
      if (tests == 3) 
        Serial.println(F("Selftest ok!"));
        while (1) // Blink OK pattern!
          digitalWrite(LED_PIN, HIGH);
          digitalWrite(LED_PIN, LOW);
        Serial.println(F("----> Selftest failed!"));
        while (1) // Blink FAILED pattern! Rappidly blinking..

  • Sorry just found the Serial.begin(230400); in the setup code. I'll start by changing it to 112500.

  • Sorry that's 115200.

  • No matter what I do I can't change the baud rate it must be set in the bootloader. Not sure why but now I'm getting 3 extra lines on bootup and not the trash at the end of the pag but so far I can't get beyond the startup page.

    Final 3 lines.

    4392 MCO:BGN:STP
    Sensebender Micro FW 1.4 - Online!
    isMetric: 0

  • So lets forget about the baud rate issue for now. At this point it looks like the program stops before it gets to the Setup routine. How about a little help please.

  • Mod

    @RWoerz forget about baud rates higher than 115200. Your board is running from internal oscillator, which is not very stable compared to crystal oscillator.
    What arduino board do you select when programming?
    I would remove the serial.begin() from your code and see if it continues to run. There is already some radio traffic with the gateway in your logging so that part (the hardest) seems to work fine 👍

  • Yes I have several other sensors working. My solar heating and 2 stage evaporative cooling system has 20 sensors on one Mega and it works fine. I just wished my Vera worked as well as my sensors. It goes down one or more times a day and sometimes it doesn't come back. I've had it replaced so who knows.

    Yes it worked without the serial.begin(). The board I pick in the Arduino IDE was a Sensebender Micro with the Atmega328 8MHz. There's no baud rate to chose from. Sometimes I get the last three line and sometimes I get junk. Might be because on the lack of the crystal on the CPU. Should I be looking into the bootloader (BIOS for us old folks) to try and change the baud rate?

    It doesn't appear to get as far as the setup routine and because I haven't figured out how to do a Serial.println before that it's hard to figure out where it gets lost. I'm used to having breakpoints and other tools to watch programs run. If I should be using something other than the Arduino IDE (that's free) please let me know. Back in another life I wrote a lot of drivers in assemble to go with I/O cards I was designing.

    BTW thanks for the help!!! I get tired of only talking to that other guy in my head.

  • Mod

    @RWoerz said in Sensebender Micro Baud Rate Issue.:

    I get tired of only talking to that other guy in my head.

    Well, at least it keeps you busy 😉

    If you paster the serial log in the log parser, you can see the library finishes setup and then enters the setup() function:
    see here

    After that the output gets garbled, due to the new baudrate. This baudrate is set in the setup(), so it definately gets there!

    If you get no output anymore on the serial console, you could also try toggling a LED or so, to get some feedback on the state of the Arduino.

    Debugging on Arduino is rather oldskool indeed...

  • Admin


    Have you chosen the Sensebender Micro (8Mhz) variant when compiling for the sensebender?

  • My grandfather told me not to get old you forget stuff. Sorry to say I lead you on a wild goose chase. Thanks for the help ends up I had an Arduino Micro hooked up on my bench I'd forgotten about. Looks like if you define it as a Sensebender Micro it will only talk to you at 230400, go figure.

    Thanks again. I know this will cost me some cred points but I hope I won't lose my secret handshake.

    Thanks again guys.

  • Sorry that was a Nano.

  • Admin

    The nano is running at 16Mhz, while the sensebender micro is running at 8MHZ.
    So when you program the nano when you have chosen the sensebender as target, everything runs twice as fast as expected, hence 230.4k instead of 115.2k for the serial port.

  • Thanks for the explanation. Makes perfect sense. In the past if there was a processor mismatch the programs would not download.

Log in to reply

Suggested Topics

  • 1
  • 2
  • 3
  • 4
  • 7
  • 12
  • 3
  • 1