The tenth blog, time really flies. I am super busy during this period at university but finally managed to find time to make the first working prototype. By first working prototype I want to say, a prototype that has the functionality that I wanted in the beginning. At this point, the S.H.E.L.F. registers when something is put on top of it, scans the shelf area with the camera looking for a label, then if the label detection goes through it uploads data online where I can view it on a phone or on a different computer. There will be one more blog after this where I'll have a user friendly code, with comments and all of that, and with some more programming features added. I haven't managed to do it to the scale that I wanted, due to other responsibilities I had in the meantime. So let's jump into the first prototype of S.H.E.L.F. Let's start of with the setup I am using to test it out. I put the sensors on two wooden planks I found laying around and am holding them in place with two simple clamps, which are more than enough for the weights I am testing at the moment. The shelf part is directly connected to the sensors with nuts and bolts. Here is a picture of the setup:
Now for the technical part of the blog. Until now all of the prototypes used only a single load cell sensor. I talked about in one of the previous blogs how it's possible to connect two load cells to a single HX711 amplifier by setting gain. This was the first method I tried using but it turned out to unreliable for some reason, and I couldn't get the second channel working properly. So in the end I had to go with the second method and that would be creating another object in the code for using another HX711 amplifier with the second load cell. This method proved very simple, and it worked without a single problem. Now to get all of it running here is the part of the code regarding the scales themselves, which can be used as a simple code by itself to calibrate the load cells in the beginning:
from hx711 import HX711 hx = HX711(5, 6) hx.set_reading_format("LSB", "MSB") hx.set_reference_unit(-215) #this is the reference that needs to be set first hx.reset() hx.tare() hx1 = HX711(23, 24) hx.set_reading_format("LSB", "MSB") hx.set_reference_unit(-204) #this is the reference that needs to be set first hx.reset() hx.tare() val = max(0, int(hx.get_weight(5))) + max(0, int(hx.get_weight(23))) hx.power_down() hx.power_up() hx1.power_down() hx1.power_up()
The code above shows just the basic work with the two load cells that we need, the rest of the code regarding the label detection has not changed compared to the last blog. For the next part I'll be talking about uploading the data online. This is a feature without which this project would be pointless. The way I did this is more of a proof of concept (though I should point out that this part will be upgraded for the final blog for sure). I decided to go with thingspeak. It's a really great and simple service to use, specially considering that the data could easily be viewed online and on a phone application. Before this I didn't have any experience with using thingspeak, but I found this great tutorial (Build Your First IOT With a Raspberry Pi, DHT11 Sensor, and Thingspeak.: 8 Steps (with Pictures) ) with a python script which I studied and just pulled out the things I needed out of it. The tutorial also goes shortly into setting up thingspeak. Now for the Android app I found a great and simple to use app called ThingView which can be found on google play (I don't know if there is an IOS, or Windows version of it). Simply said all that is needed is to the enter the read API key that can be found on thingspeak. Now for the code on the Raspberry that uploads the data online. Similarly to the app we will need a write API key that can also be found on thingspeak.
import urllib2 myDelay = 5 myAPI = "This is where the write API key goes" baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI print baseURL #This next part of the code is in the section where the label detection went as it should try: f = urllib2.urlopen(baseURL + "&field1=%s" % val) sleep(int(myDelay)) print f.read() f.close() except: print 'exiting'
This code is made to write only into the field one which is the main thing I plan on changing, the idea is of course to upload it to corresponding channel depending on the label. This will of course require to have the channels premade and to know which is which, in the same way I stored data on the Raspberry. So now with all of that connected, here is are the results, as I did in the one item shelf blog, for testing i used my phone with a label picture loaded. Firstly here is a picture of the phone's mass measured on a store bought scale:
And here is a screenshot of my phone showing what I got when testing out the prototype
And with that I would like this finish up this blog. I am really happy to see all of the parts of the project working together as a whole. This has been a really fun challenge. I will have another blog after this one where I'll do a recap on everything that has been done, can be done and stuff like that, with the use friendly code, step by step guide and the upgrades for this prototype which will make just a tiny bit better. Thanks for reading the whole blog, hope you liked it!
Milos
Top Comments