more G-Labs products

Author Topic: Need Basic help with TMP36  (Read 2087 times)

December 10, 2015, 03:02:31 AM
Read 2087 times

kb1ojr

  • *
  • Information
  • Newbie
  • Posts: 10
Hello all.

I am new to this Arduino / homegenie stuff so go easy.

Right now I have my Ardunio hooked to A Pi2, all is working. I would like to simply add my tmp36 Temperature sensor and a widget on the dashboard. I have successfully uploaded a code to the Sketch and created the program for it, I am sure it is monitoring temp, but I do not know how to add it to the dashboard, can someone point me in the right direction or documentation explaining on how to do this. It would seem everyone else who has a tmp36 sensor uses some other board in the mix to complicate it for me.

Thank you in advance.

December 10, 2015, 03:00:06 PM
Reply #1

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
-Go into HG Menu configure - groups - dashboard
-Bottom right actions - add module
-Scroll down to find the module you are looking for, the names here are organized by program name, so look for that
-After the widget is in the list, you can drag it to move and add seperators to help group them

If you have trouble finding expected module, in the HG program code for your arduino there should be something like this to define the actual module/widget:
Code: [Select]
Program.AddVirtualModules("HomeAutomation.ArduinoBsmtUtil", "Sensor", "homegenie/generic/sensor", 1, 1);


December 10, 2015, 04:00:15 PM
Reply #2

kb1ojr

  • *
  • Information
  • Newbie
  • Posts: 10
So the code you supplied should be added under the Program I added called Arduino, and on the makefile tab specifically for the TMP36 sensor that I created?

December 10, 2015, 05:05:32 PM
Reply #3

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
Not familiar with the makefile tab, I am not using the HG Eden board arduino integration.  My arduinos just generate JSON and HG parses.  So in HG I think these are the key codes to pull in the JSON data and send it to widget with RaiseEvent:

Code: [Select]
//////startup code
Program.AddVirtualModules("HomeAutomation.ArduinoGarage", "Sensor", "homegenie/generic/sensor", 3, 3);
//////program code
var module3 = Modules.InDomain("HomeAutomation.ArduinoGarage").WithAddress("3").Get();

  var json = Net.WebService(webserviceurl).GetData(); 
//example json data string generated by arduino {"door1":"0","door2":"0","motion":"0","temperature":"73","humidity":"33","light":"0","uptime":"23937"}
  tempf=json.temperature;
    Program.RaiseEvent(module3, "Sensor.Temperature", tempc.ToString(), "Temperature");


December 11, 2015, 01:28:34 AM
Reply #4

kb1ojr

  • *
  • Information
  • Newbie
  • Posts: 10
You lost me.

I am using just a Raspberry Pi2 with an Arduino UNO, in the Arduino is a TMP36 sensor. I just want to add that sensor to my homegenie dashboard. I figure this should be a simple task to help me understand how to proceed with the rest of my project.

December 11, 2015, 01:44:49 PM
Reply #5

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
Sorry, you confused me when you talked of the makefile tab ;-)  Have you confirmed the temperature data is getting into HG?  Or do you have just the physical/electrical connections between Pi and arduino?

If you have the data confirmed in your HG program with something like Program.Notify("temp",temp); then you need to add the code above to that program .  It will create a 'virtual module' (in the code mine is ArduinoGarage).  Then your program will send data to it with the Program.RaiseEvent.

Once you have this code running, the virtual module will show up as a widget you can add via the steps in my first reply above.


December 11, 2015, 03:38:38 PM
Reply #6

kb1ojr

  • *
  • Information
  • Newbie
  • Posts: 10
That would seem to be where I am stuck, I am not sure how to verify the data from the TMP sensor is coming to the Arduino, I am however able to modify the arduino sketch for the blink template and get that to work. Also when I check the Temp sensor in the sketch serial monitor I can see it reporting. I think I just need to get the homegenie to read it off the arduino, that is where I seem to be confused.

So from the start I want to go to configure > programs > add groups > add new program > name tmp36 > change program type to Arduino sketch ... then go to sketch code and paste the following

/*
 * For documentation see http://arduino.cc/en/Tutorial/Sketch .
 * After compiling, use "Run" option from "Actions" menu to upload this sketch to your Arduino board.
 */
#include "Arduino.h"
//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures
 
/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  Serial.begin(9600);  //Start the serial connection with the computer
                       //to view the result open the serial monitor
}
 
void loop()                     // run over and over again
{
 //getting the voltage reading from the temperature sensor
 int reading = analogRead(sensorPin); 
 
 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = reading * 5.0;
 voltage /= 1024.0;
 
 // print out the voltage
 Serial.print(voltage); Serial.println(" volts");
 
 // now print out the temperature
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((voltage - 500mV) times 100)
 Serial.print(temperatureC); Serial.println(" degrees C");
 
 // now convert to Fahrenheit
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 Serial.print(temperatureF); Serial.println(" degrees F");
 
 delay(1000);                                     //waiting a second
}



>> then compile > run ... This successfully uploads homegeneie says. This is as far as I can get.


I am not sure where to add the programming specifically, do I make a new program called temp with program type C# or Arduino Sketch? then add those codes to "program code" and "stratup code"



December 11, 2015, 04:15:28 PM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
as already said in this forum, beside the arduino sketch, you also need an automation program that reads the data from arduino and put it on a virtual module.
See the Eden V2 example program:

http://sourceforge.net/projects/homegenie/files/testing/

EdenV2_Firmware_1_1.zip is ---> the Arduino sketch
EdenV2_Module_1_1.hgx  --> C# program to read data from arduino and make it available through a virtual module


g.

December 11, 2015, 04:42:44 PM
Reply #8

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
I didn't realize we could have Arduino sketch in HG, maybe I did and forgot... however, I don't see that option for arduino sketch in my HG program editor now.

So... you'll need to read the serial data from arduino into HG then.  There is a serial port i/o test program, copy that code.  Then you'll need to parse your data from arduino.  I have my arduino sending CSV data, so I parse it something like this (you should look for a better example as my code is messy, I have been planning to switch to a web interface between arduino and HG on Win7 PC)

Code: [Select]
Action<string> HandleStringReceived = (string message) => {
 if (message.IndexOf('\r') != -1)  {
    string[] data = message.Split(',');
    int temp= (int)double.Parse(data[3]);

You can find Gene's more robust code here for his "Eden" board which is arduino connected to Pi.
http://www.homegenie.it/docs/diy/eden_v2.php
I still don't see the arduino sketch feature in HG, tried importing the eden firmware per the instructions and it didn't seem to do anything (no new program added)- HG Arduino Sketch support isn't for Win7.

You might change your post title to include arduino because that is really the topic here, might trigger someone else to help better than me :-)
« Last Edit: December 11, 2015, 04:52:18 PM by kevin1 »