Raspberrypi Current and Temperature Sensor Adaptor: Difference between revisions
Line 62: | Line 62: | ||
45,54,19.46 | 45,54,19.46 | ||
47,56,19.46 | 47,56,19.46 | ||
[[Why do I see a different output?]] | |||
==View the data with Python== | ==View the data with Python== |
Revision as of 13:51, 24 January 2015
A current sensor and temperature adaptor for your Raspberrypi. It connects to the GPIO connector and provide data via serial interface. An Atiny85 mcu run the board and can be re-programmed easily with your Arduino IDE.
There are several options for logging and viewing the data. Python or Emoncms or anything able to read a serial port.
There are currently four models of the board.
- 1 single CT
- 1 CT and 1 temperature sensor.
- 2 CT and 1 temperature sensor.
- 3 CT.

Technical Specifications
Designed for AC current only.
Current Sensor
Recommended sensor: SCT-013-000 50mA/100A
Burden Resistor: 18Ohm
Connector: 3.5mm Jack
Default Voltage for power calculation: 240V (can be modified in firmware)
Temperature Sensor
Connector: 3.5mm Jack
The intended temperature sensor is the DS18B20 which can be configure in either parasite or normal mode.
The connection to a 3.5mm jack connector is shown below.
View the data from Linux terminal
It is possible to read the data output directly from a linux terminal. i.e. reading the serial port.
Before hand you must ensure two things before getting this to work:
1/ The firmware of the board has been set to use output as CSV. Relevant sketch can be downloaded below. See OUTPUT_AS_CSV variable.
2/ The ttyAMA0 serial on the raspberrypi is free. See this link here.
The output from the adaptor board will be in the format below. power in kw. temperature in deg celsius.
power1,power2,temperature
Then on the Raspberrypi you can issue the commands
$ stty -F /dev/ttyAMA0 raw speed 9600 $ cat /dev/ttyAMA0
The terminal should then show something like this below
pi@raspberrypi ~ $ cat /dev/ttyAMA0 46,52,19.46 47,52,19.46 45,54,19.46 47,56,19.46
Why do I see a different output?
View the data with Python
Using the same sketch as mentioned above a python script can be used to work with the data. The example script below will be a good starting point.
First of all make sure you have python-serial package installed
$ sudo apt-get install python-serial
Then copy the following into an executable file and run it.
#!/usr/bin/python import serial ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=1) ser.open() try: while 1: response = ser.readline() z = response.split(",") if len(z)>=2: print "Power 1: %s Watts" % z[0] print "Power 2: %s Watts" % z[1] print "Temperature: %s Degrees" % z[2][:-2] except KeyboardInterrupt: ser.close()
The above example is for the board with 2CT and 1 temperature sensor. See here for the python example using the board with three CT sensors.
Record the data with EMONCMS
The Raspberripy OS distribution provided by OEM for the Raspberry emonbase must be used for this purpose. The default sketch will work for the use of EmonCMS.
The Adaptor emulates a RFM12Bpi unit communication pattern. i.e. What will be sent to the Raspberrypi serial port will look as if it was sent by the RFM12Bpi.
The sketch is provided below. Make sure the OUTPUT_AS_CSV is set to false in the sketch.
Program the Attiny85
The onboard mcu can be re-programmed to your needs. This link is a tutorial to upload Arduino sketches to the Attiny85.
The board does not have any SPi port. The chip will have to be removed from the board manually.
Files
Arduino Sketches
2CT 1Temperature (v1.3)
3CT (v1.0)
Remember to modify the OUTPUT_AS_CSV variable to choose between csv or emoncms output.
Note. Power calculation is based on a voltage of 240V.
Related Howto
Free up the ttyAMA0 serial port