Friday, February 27, 2015

[Wireless Room Temperature Monitoring System] Sending Temperature values to the Raspberry Pi and store it in a .txt file

Now that each elements are working independently we will have the arduino measuring the temperature, sending it with the TX 433 Mhz module through the air and have the Raspberry Pi pick up the data and collect it in .txt file

I had to modify the Arduino code in order to get the temperature with full details. The device is giving a float value that cannot be sent over RF (basically we loose the numbers after the comma). In order to avoid that we multiply the float value by 100 in order to get full details and send it over RF.

I modified the "printTemperature" class from the Arduino Code :
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  int tempCx100 = (int)(tempC*100); // Multiply the float value > int with 4 digits

  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
    mySwitch.send(0000, 24);
  } else {
    Serial.print("C: ");
    Serial.print(tempC); //reads the temp value on the serial port
    mySwitch.send(tempCx100, 24); //Temperature x100 with all the accuracy needed
  }
}
On the receiving end, I modified the code in order to modify the received Int into a float and to store the value received in a file.

Modification of the while loop within the RFSniffer.cpp program
 while(1) {
      if (mySwitch.available()) {
        int value = mySwitch.getReceivedValue();
        float valuefloat = (float) (value/100.0); // Divide the received value to get a float
        if (value == 0) {          printf("Unknown encoding");        } else {
          printf("Recu %i\n", mySwitch.getReceivedValue() );
          FILE *f = fopen("/home/pi/recu.txt", "a"); //append the value within the next line of the recu.txt file          fprintf(f,"%i\n",value );
          fclose(f);        }
        mySwitch.resetAvailable();
      }
There you can see the reading directly on the Serial Port reader from the Arduino Software


Then there is the value being sniffed by the Raspberry Pi directly in the Terminal


And finally the content of the file in which we are appending the received file indefinitely

Now that this work, here are the next challenge.

I need to be able to "identify" which Temperature sensor sent this result, basically label the sent value
I need to append those values into a file per day with the time stamp available
Ultimately i should be able to have those values read and plotted in a graph.

Friday, February 13, 2015

[Wireless Room Temperature Monitoring System] Temperature sensing with DS18B20 sensor and Arduino Pro Mini

The goal here is to plug the DS18B20 Temperature sensor to the Arduino Pro Mini.
For my project i decided to go with an already complete module with the sensor as well as the 4,7 kOhms ... less soldering !

The wiring : 

The DS18B20 Module has 3 pins just like the DS18B20 sensor alone.

      DS18B20 Module > Arduino Pro Mini

  • - (Negative) > GND
  • + (Positive) > VCC
  • Data > Pin 3 
























The software :

Once the wiring is all done, the next step is to try finding out what is the address of the sensor in order to get the temperature measure later on.

You need to install the OneWire and the DallasTemperature libraries
- One wire : http://www.hacktronics.com/code/OneWire.zip
- DallasTemperature : http://www.hacktronics.com/code/DallasTemperature.zip

The idea is to upload the following code to the Arduino Pro Mini with the sensor wired :
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire  ds(3);  // Connect your 1-wire device to pin 3
void setup(void) {
  Serial.begin(9600);
  discoverOneWireDevices();
}
void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  Serial.print("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr[i] < 16) {
        Serial.print('0');
      }
      Serial.print(addr[i], HEX);
      if (i < 7) {
        Serial.print(", ");
      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}
void loop(void) {
  // nothing to see here
}
code source : http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

Once up and running with the program in the Arduino, go to :

Tool > Serial Monitor.

The sensor address will then show up on the monitor. In my case it was :
0x28, 0xFF, 0xED, 0x0F, 0x11, 0x14, 0x00, 0xD2 
With this address we can move on to the next and final step, measure some temperatures finally !
Upload the following code to the Arduino Pro Mini
#include <OneWire.h>   
#include <DallasTemperature.h>
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress Thermometer = { 0x28, 0xFF, 0xED, 0x0F, 0x11, 0x14, 0x00, 0xD2 };
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(Thermometer, 10);
}
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}
void loop(void)
{
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();

  Serial.print("Inside temperature is: ");
  printTemperature(Thermometer);
  Serial.print("\n\r");
}
Code source : http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

Once the Arduino is running the program, go to the Serial Monitor again.
The temperature should be printed on the screen
















Tada ! Temperature is displayed on screen !

Next step is to try and combine the temperature sensing and to send it via TX 433 Mhz to the Raspberry Pi to sniff !

If anyone has any idea on how to do that ... i am interested !

[Wireless Room Temperature Monitoring System] Sending a value through RF 433 Mhz Module from an Arduino Pro Mini 5V

Now that i have successfully programmed the Arduino Pro Mini with a simple blink program, i need to take it to the next level and try to send some data through the TX 433 Mhz module.

For the wiring :

The TX 433 Mhz pin are to be connected as following:

  • VCC > Any VCC pin on the Arduino Pro Mini
  • GND > Any GND pin on the Arduino Pro Mini
  • Data > Pin 10 on the Arduino Pro Mini
Here i am using the FT232RL module to power the Arduino Pro Mini, but ultimately i will plug a 9V Battery as source of power



Now from the Software side :

First download and install the RCSwitch library : https://code.google.com/p/rc-switch/

Once done you can compile and send the following code to the Arduino Pro Mini

Sending data code :
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  // Transmitter is connected to Arduino Pin #10
  mySwitch.enableTransmit(10);

  // Optional set pulse length.
  // mySwitch.setPulseLength(320);

  // Optional set protocol (default is 1, will work for most outlets)
  // mySwitch.setProtocol(2);

  // Optional set number of transmission repetitions.
  // mySwitch.setRepeatTransmit(15);

}

void loop() {
  /* Same switch as above, but using decimal code */
  mySwitch.send(5393, 24);
  delay(1000);
  mySwitch.send(5396, 24);
  delay(1000);

  /* Same switch as above, but using binary code */
  /*mySwitch.send("000000000001010100010001");
  delay(1000);
  mySwitch.send("000000000001010100010100");
  delay(1000);*/

  delay(2000);
  //mySwitch.send(4212181, 24);

}
Note this code is not from me at all. source : http://www.homautomation.org/2013/09/21/433mhtz-rf-communication-between-arduino-and-raspberry-pi/

On the receiving end, we have the RX 433 Mhz module plugged in the Raspberry Pi (Receiver : Pin 13 (GPIO 27 Rasp Pi B+). Also marked as Pin 2 under WiringPi's naming convention)

I am basically using the same setup (RFSniffer code etc ...) as explain in the following post : Link

And it works ! The Raspberry Pi successfully sniffs the code sent (5393, 5396)


Looks like that all the send messages were not picked up, only 1 within the loop (4 digit long) the other two are longer and i am not sure they are being picked up by the RFSniffer program.

Yay, that is big for me that is not an electronic expert :)

Next i will try to make the DS18B20 independently with the Arduino Pro Mini

Thursday, February 12, 2015

[Wireless Room Temperature Monitoring System] Program the Arduino Pro Mini through USB Serial FT232RL Module

First step to work on an Arduino Pro Mini project is to actually manage to program the processor in order to have it behave the way you want.

The wiring :

From FT232RL to Arduino Pro Mini the wiring is done as following :

      FT232RL > Arduino
  • DTR > DTR
  • RX > TXD
  • TX > RXD
  • VCC > VCC
  • CTS > GND
  • GND > GND
Then the FT232RL is connected to my Macbook Pro through USB Mini




The software / computer :

Install all the necessary drivers to allow the mac to use the FT232RL USB Serial : http://www.ftdichip.com/Drivers/VCP.htm (version 2.2.18 for Mac OS X)

Install the Arduino software : http://arduino.cc/en/pmwiki.php?n=main/software

At first i couldn't have a successful connection between the computer and the Arduino but after some trial and error here are the different settings/selections within the software :

Tools > Board > Arduino Pro or Pro Mini (5V, 16Mhz) w/ ATmega328
Tools > Serial Port > /dec/cu.usbserial-A50285BI (which i assume is the reference of my FT232RL)
Tools > Programmer > Arduino as ISP

I threw in a small blinking led program to test if the code went through :

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(50);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(50);              // wait for a second
}
code source : arduino software example library

After verify the code, i then upload the sketch to my Arduino Pro Mini, here is the result :


And, bim the light is blinking fast ! Upload successful