Tapatalk

Adding more voltages to Voltage.node example

Adding more voltages to Voltage.node example

5

PostNov 24, 2016#1

I am following along on the examples for Voltage.node and Voltage.base. How would I add another voltage to this example ? I am not sure where the voltages are currently read ? I assume they are called from #include <T2WhisperNode.h> or #include <RH_RF69.h>, but it's cryptic to me.

Either a example tutorial or adding more comments to the examples would really help

thanks
Randy

1885
1885

PostNov 24, 2016#2

Hi Randy,

I didn't understand what you mean by "Adding another voltage". Could you please explain a bit more what are you planning to do?

Regarding the example, it shows how to "prepare" a message using a pre-determined format and fill the last two bytes of the "myMsg.data[]" with the actual voltage reading and send it to another node, which will unpack the "myMsg" and print on the screen.

The voltage reading is done using the function T2Utils::readVoltage, which is defined in the files src/utils/T2Utils.h and src/utils/T2Utils.cpp

Here the voltage code function:

Code: Select all

uint16_t T2Utils::readVoltage(uint8_t analogPin, uint8_t controlPin, uint16_t maxVoltage, uint8_t samples)
{
  analogReference(INTERNAL);

  // Turn on the MOSFET via control pin
  if(controlPin > 0)
  {
    digitalWrite(controlPin, HIGH);
    pinMode(controlPin, OUTPUT);
  }

  // Read pin a couple of times and keep adding up.
  uint16_t readings = 0;
  for (uint8_t i = 0; i < samples; i++) {
    readings += analogRead(analogPin);
  }

  // Turn off the MOSFET
  if(controlPin > 0)
  {
    digitalWrite(controlPin, LOW);
  }


  /* Uncomment for Debug */
  /*
  Serial.print(F("AVG last X Analog Reads on analog Pin: "));
  Serial.println(readings / samples);
  Serial.print(F("Max Voltage: "));
  Serial.println(maxVoltage);
  Serial.print(F("Calculated voltage: "));
  Serial.println((uint32_t)maxVoltage * (readings / samples) / 1023);
  */

  /*
   * This need to be casted over 32 bits to allow proper calculation.
   * Still safe to return a 16 bits for results up to 65V
  */
  return ((uint32_t)maxVoltage * (readings / samples) / 1023);
}
Also, you can have a look on the RFM69 examples from RadioHead, they are very simple and should work without modification (only Frequency maybe).

Not directly related to the question, but might help:
Unfortunately the Arduino IDE is a very simple "Text Editor" that does not allow source-code navigation. This makes very difficult to explore libraries and others people code. I personally like to use Eclipse to write the C/C++ code, which allows to easily navigate over the source code. I tend to use this modified version of Eclipse: http://eclipse.baeyens.it/stable.php?OS=Windows - It might take a few frustrating hours to get it working, but it's a well spent time.

Sophisticated text editors might also assist with that, like Sublime. Some people just use a "real" IDE to write the C/C++ code, and get back to the Arduino IDE only for compiling and uploading it.

Hopefully Arduino would move toward a proper IDE in the future.

5

PostNov 25, 2016#3

Thanks, this does help. I simply wanted to add another voltage (say a thermistor to measure temperature) over the link. The 2 battery voltages are great, but next I need to add temperature.

I did not realize that the voltage.node and base.node called the Utility T2Utils to read a voltage, as you mentioned it's not obvious using the Arduino IDE.

I have tried to read all your documentation before asking for help. Now I know to look into all the library files for more help. This is a very cool product, it's just a little over my head, but hey I'm learning.