Introduction

 

First of all many thanks to everyone for the words of encouragement. Every pat on the back is much appreciated so Thank You.

 

bee.jpg

This should have been multiple posts but ... I was going to skip this week's post but ever since I found out that this would be the last minion of the week, I wanted to get this one out for a chance for the same. If by some chance, I do get it, I have something very special planned. (Fingers crossed and tongue at the right angle)

 

(I will be putting ALL THE CODE on github soon after I clean up the formatting.)

 

I have ended up a circus of sorts and while I am running behind schedule, I am trying hard to recover. Last week was I panic struck and my post reflected the same. With encouragement from the greats, I have gathered the courage for this week's work.

 

Updates! In addition to the RPiSOC, I received the CC3200 board as a part of a roadtest offered by element14. First off, this piece of equipment is amazing. Second, the feature set is really amazing- it can run wifi on two AA batteries for an entire year. I will be running it off the TI Fuel Booster pack which will also be taking a count of the battery status. I already have the code ready but until I have the rest of the module ready I will not be posting details today. I will however be sharing some details on how to work on it. This week I worked up the modules with the wireless connectivity to OpenHAB.

 

There are three module that use wireless connectivity in my project with custom hardware.

  1. The MET system with the CC3200 which is using MQTT to talk to the RPi and then OpenHAB. I demonstrated MQTT and Arduino in my last post : MQTT+Arduino+(Tektronix Scope and IR Remote + A little brain power). and the principle applies here as well.
  2. The Weighing system for LPG cylinders with capacity of 50Kg. This has a lot of use in our house and additionally I wanted to demonstrate how simple it is to interface RF systems with RPi and OpenHAB
  3. The Application Current Monitor- Again of extreme utility and I wanted to demonstrate the flexibility of the EnOcean Sensors.

 

The decision - which RF technology is better- AM Modules? XBEE? nRF? Wifi? Bluetooth? TI CCxxx modules?

 

I have been struggling with the decision for the wireless technology to be used with two of my modules. The first module was bound to use Wifi and MQTT. The second module uses a load cell or weight sensor and the third uses a current sensor. Out of the two, the load cell module should be run off a battery since it will be placed near an LPG cylinder. I don't want anything sparky nor do I want the module to be particular about sunlight or other light sources. Hence my requirement was of something batter operated while low power and wireless. All these are met by my favorite company TI's MSP430 and a wireless module. I had used the CC2400 module in a previous challenge but the code was rough and not really fantastic. Hence I decided to overhaul the code and add little bits and pieces. I will be running this off 2 AAA cells and testing.

 

ez1.png

 

The next decision was for the current sensor. I will be measuring the current a sensor I got from E14 but the input will need to be conditioned. The selected current sensor will generate a maximum voltage of 0.333 Volts at 50Amps- Thats right! its that small. There are a number of ways to measure the 333mV of output and I would have liked to have a buffer opamp stage but I dont need another component to waste energy. The simpler method is to fashion the Temperature module STM330U directly to the CT sensor... or so I will try.

 

ct.png

 

I wanted to use the TCM320U for the current sensing app which is a wonderful module and I wrote some code around it, but its not fitting in right now. I will be discussing these two in detail in an upcoming post.

 

MET system, CC3200 and MQTT:

 

The principle of MQTT is simple and how to set it up was explained in my previous post. The difference here is that the Arduino does not have the horse power to do SSL/TLS which means no security. But that's OK since its mostly going to be local traffic. The CC3200 comes in with an ARM M4, a lot more ram and a WiFI module. Not only can I connect to a local MQTT service, I can also connect to the Internet and retrieve some other weather forecast data and operate independently- even if OpenHAB is not working.

 

There is a great tutorial on the implementation of MQTT on the CC3200 using PAHO by Benjamine Kabe of the Eclipse foundation. I will be doing a dedicated post on this later. I will be connecting the CC3200 to custom sensors and a battery booster pack. I will be posting MET data as well as Voltage and Current data. Additionally I will be charging the entire system OFF a solar cell. The diagram is given below.

 

cc3200 me.jpg

IOT Weighing Machine: A Low Power Sensor Network using the CC2500

 

My goal is to read the weight of a LPG cylinder using a load cell, interface it to a microcontroller and transmit it to OpenHAB. Then use OpenHAB to plot graphs and generate alerts and all kinds of stuff. The CC2500 module is a bit old and I have had it for some time. It operates on 2.4GHz which means it wont interfere with the EnOcean Modules. The module has an MSP430 and the CC2500 and a chip antenna.

I basically needed to write the code for the transmitter and receiver. Note that the cc2500 is capable of duplex communication ie it can transmit and receive as well. For my application I need the node to transmit and sleep. I don't need to receive hence I will later on convert this module from cc2500 to an ASK cheapo module but will retain the msp430. Hence I need the field module to...

  1.      Read ADC values
  2.      Transmit to base
  3.      Set wakeup and Sleep

 

Additionally I don't want the load cell to keep draining my battery. I will be transmitting ADC data after the max delay possible. So I want to be able to switch off the load cell as well. For this I will add a MOSFET to turn off supply to the load cell when not in use. This means I also need to...

 

     0.1 wake up the load cell

     0.2 wait a bit for the circuit to start up and stabilize

     1.1 switch off the load cell ckt

 

I also need to check if the load cell ckt will work from 3v or not... Let's start the experiment.

 

Step 1. Testing the load cell.

 

Now these load cells are essentially be train gauges which will produce a very small change in resistance when force is applied. This means that for a fixed voltage V, a small change in resistance R will result in a proportionally small change in I... Ohms law. Sounds simple but the current is of the order of Milli or nano amps. The situation is made worse when the ADC will draw more current to convert. In short very small changes are hard to measure. To remedy this we have op amps which can amplify signals and have a very large input impedance and not loaf the sensor. A special class of op amps called Instrumentation Amplifiers are designed and manufactured for accuracy and I will be using the TI INA125

 

It is a standard for these type of applications and solves a lot of problems. You can try to make an instrumentation amplifier using something like lm324 but it as just not the same. I tried but the results were distressing. It worked but for really high gains of 50000 and above not good.

 

The load cell was purchased from China based seeedstudios and I think these are the same ones that are used in digital weighing machines. The circuit for the same is shown below.

 

ina125.PNG

 

 

I tested it out on the bread board and the results are in the video.

 

Demo of the INA125 with a 50Kg Load Cell on a Breadboard

 

Step 2: Prototype and test

 

The next step is to put it on a PCB. I used a general purpose PCB for now. The reason for not making a dedicated PCB is that I don't have the time right now. I will be sending one to Oshpark soon though. Another thing is that I will be adding onboard controller and a different rf module. A major reason for using the cc2500 is because I have the kit. The base station has USB to serial converter which works out of the box for the RPI... I tested that first. I got FTDIs which I will interface to the custom rf module but much later.

 

So the first part is the amplifier circuit. The next part is switching it on and off. I will be using the irf530 MOSFET because that's what I have lying around. I did a spice simulation to test it. The threshold voltage is around 2.2v which is less than the 3v power supply.  I have some more breadboard testing to do on this so I wont put it on my first prototype. The pins are brought out for the loadcell and battery. The last part is the microcontroller. Since I am using the kit module I have a female row connector right now. For my final solution I will have the msp430 onboard.

The final circuit looks like this.

 

ina125b.PNG

 

I did spend 2 days or I should wasted two days on the analog part with a stupid problem which caused my output to jump around a lot. But I did get it to stabilize and got the system setup. It worked!

IMG_8907.jpgIMG_8908.jpg

IMG_8911.jpg

 

Step 3: Spec and Write the Code

 

The first thing to do is understand the ADC that will be used. The MSP430 has an ADC10 which is a 10bit ADC. This means I can get 2^10 or 1024 at Vreff. I am using 3V from two AAA cells which translate to 3000mV/1024. This equals roughly 2.93 milliVolts per bit. I will be using this calculation to convert the ADC data into voltage data which I need for OpenHAB.

 

The next step is to write code. I wrote two separate firmware for the station and node. The node is designed to use LPM3 which disables everything and lets just a low power clock to be used for the timer. The algo is simply...

  1. The timer interrupt wakes up the node,
  2. sets up the ADC and sleeps,
  3. wakes up on ADC interrupt and then
  4. transmitts the value in ASCII
  5. resets its alarm and
  6. goes back to sleep.

 

It is not that complicated, just took me a little longer than expected. I did the entire coding with comments compatible with DOXYGEN. It's a tool that will generate documentation automatically from code so my final report will be a lot easier on the eyes. Additionally I got to learn a lot of new things. The code need a bit more clean up and once I am happy with it, I will be uploading it to github. I took down the existing repo and refined it a LOT! The code is already more cleaner and runs leaner.

 

Step 4: Test the code... on the RPi

 

It took a lot of iterations to get the code just right. The data has a start character ':' just like modbus but no address. I was able to get minicom on the RPi to display the data as it came in. The screenshot is given below.

 

minicom.PNG

 

Step 5: Power analysis... featuring the Tek Scope.

 

In order to measure the power consumption of the system I use my faithful 1 ohm resistor and the output was plotted on the scope. The current consumption profile with the prototype is as follows.

 

TEK0005.JPG

I did not do the numbers but technically I should be consuming around 2.7mA max

 

 

Step 5: OpenHAB integration. The serial binding

 

 

All this was about having OpenHAB display and do stuff with the data. Now I formatted the data as a string. A start character ':' followed by four characters letting me the millivolts being measured at the ADC. With no load I set the output to be around 95 milliVolts. Since I am running 2.93millivolts per bit on the ADC I need to convert this into weight... or Do I? I just need values for empty and full. The in-between and exact values I don't care for in this project. Note that the module can be easily calibrated if required. These load cells are used in weighing machines

 

 

We need to do the following sub steps:

 

Step a.

The first thing we need to do for openhab is to add the serial port binding to the addons folder

 

Step b

In the start script, we need to add

 

-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0:/dev/ttyACM0




 

Step c

In the .items file, we add a new item as:

 

String loadCellString "Load Cell [%s]" (Sensors) {serial="/dev/ttyACM0"}




 

Step d

Startup OpenHAB and connect the EZ430-RF2500

 

Step e

Convert String to Number: We cannot plot strings so we need to convert it into Number data and then apply rules for generating notifications and events. This is done in two parts:

 

     a. The first is to create a separate item for the number value

     b. Use rules to convert the string to number and post it to the item.

 

I simply created an item as

 

Number loadcell "Load Cell [%.1f mV]" <cistern>     (Sensors)




 

Next the rule:

 

rule "LoadCell"
when
       Item loadCellString received update
then
      var String temp = loadCellString.state.toString.trim

      var int start= temp.indexOf(":") + 1
      var String temp2 = temp.substring(start, temp.indexOf('mVolts'))
      var Double loadCellValue = new Double(temp2)
   
      loadcell.postUpdate(loadCellValue)

end




 

Copy paste for multiple values if received by the serial port. JS rocks!

 

Thats it. The data is displayed as:

 

loadcelldata.PNG

 

 

 

I used a vice in the video to demo the weight change. I am working on hanging the gas cylinder on the load cell. I will also modify the voltages to be converted into %ages at least. Its as simple as getting the full and empty values and then dividing the range. One rule away

 

Step e

The final PCB and the mount.

 

I am a bit behind on the fabrication part and the way to hang the cylinder is bit of a challenge. The LPG cylinder is potentially explosive and I don't want to rush it. I have an idea but will have to try it before I show it on the blog.

 

Module wrap up

 

This completes this module and I actually I felt like things are coming together.

 

 

IOT Current Sensor : Monitoring currents: Hacking EnOcean

 

 

This took some time to figure out how to work with. I could have used an XBEE but no. I then moved to the EnOcean STM330U which is basically an energy harvesting temperature sensor. I went around in a lot of circle because fo a couple of reasons. I thought I could add the current sensor to the TCM320U module which I can program and then send the data to the EnOcean Pi. The problem is that the existing OpenHAB binding does not support all the equipment profiles. We need a custom profile. There were posts last week on "man vs bindings" which gave an account on how to make a custom binding.

 

I am not very good with java and so I thought up a different method...

 

What we did was...

 

The existing EnOcean STM330U modules are designed to transmit temperature. The OpenHAB EnOcean Binding reads it and converts it into numbers. It does not care it it receives 100 degree celcius. To the binding, its just receiving a number. My concept is to hack the STM330U module to read an analog voltage using an ADC and then transmit it as number in the same format as the temperature. OpenHAB will gladly receive it like before and I can parse it to whatever I want Simple!

 

Step 1:Setting Up

The first thing to do is to get into the code for the STM330U. I did a post on how to program an EnOcean module here... IP post 9: EnOcean Programming: Blinking LED on the TCM330 : For minion Dave!

 

The API comes with an example code for the firmware and I already conveyed my thanks to the author. Now C I understand. The provided Programmer Board by EnOcean was given to us for this very reason.... I think EnOcean if I am wrong- sorry.

 

Step 2: Understanding The Hardware

 

The STM330 hardware is as follows:

st1.png

So we get ADIO0,1,2,3,4,5,6,7 on the pins can I use em all?

st2.png

Step 3: Dissecting The Code

 

I need more info so I decided to open up the exsiting firmware. In the existing code, there is...

  • a function named: Measure which does all the ADC Stuff.
  • b function named: Measure2Data which converts the data into a telegram
  • c function named: sendDataTelegram which sends the telegram prepared

 

Very systematic... I wrote the MSP430 code very similar to the way it was written for the EnOcean module.

 

Step 4: Using Dolphin Studio

 

So I need to modify the code to read the ADC. This can be done manually but you may use Dolphin Studio to generate the correct startup and configuration code. The screenshot below show us how easy it is to generate the startup code. I already understand the code pretty much hence I made the changes.

 

dolphin1.PNG

 

I then put my TCM320 on the board and started Dolphin View Advanced. I put the TCM320 in sniffer mode and that thing is EXTREEEEEEMLY useful. Take a look.

dolphin adv1.PNG

 

Now the new firmware needs to be configured to enable the ADC. Did that. I connected a pot to the provided board and for a value of 0, the packet data changes from 0A in the above screenshot to 00 which is displayed by the system as 40 degree C.

STM0txn.png

So effectively we have hacked into the STM330U Hardware. Fantastic

 

Step 5: The Current Sensor

 

The next step is understanding the current sensor. I am using the SCT-0400 from MagneLabs. This was expensive but worth it. The datasheet tells us that with a 50Amp of current on the sensor side, we get a 333mV at the output. I wanted to make this entire sensor Energy Harvesting! The max output is 333mV and it fits in with the 1.8V max. The graph is as follows:

grp.png

The output is AC. I will try to get the scope in position to read the values but dont have anything to show right now. We need to convert this into DC. If I use a simple diode, the knee voltage of 0.7 volts for Silicon diodes and 0.3V for schottky devices. This means I cannot connect it directly to the STM330U

I was thinking...

 

2014-09-21 15.36.46.jpg

 

I will need to calibrate this but it works!

The final unit looks like this...

 

IMG_8912.jpg

The coin cell battery is behind the module itself.

Step 6: Configuring and calibrating

 

I am getting a number and what I need to do is either calibrate it locally in openhab via rules or in the 8051 itself. The challenge is to have a reference. This step is on my todo list and will be finished once I can get to my university electrical lab.

\todo

 

Conclusion

 

This week I got some things done. The EnOcean Modules are great and my familiarity with 8051 is paying off. I got something done and I learned stuff in the process. I did bite off more than I can chewed but Im getting there.

 

The Raspberry Pi Rover

 

I am also pleased to preview the RPi Rover for my project:

 

2014-09-05 11.01.50.jpg

 

Does not look like much but next week, this casserole with wheels will have the RPiSOC driving it around the house. I will have a demo video next week for what I already have up and running.

 

Thanks for reading.

Cheers,

IP