Previous posts for this project:
- [CaTS] ForgetMeNot - Index
- [CaTS] ForgetMeNot - Week 0: Project Description
- [CaTS] ForgetMeNot - Week 1: EnOceanPi and Sensors
- [CaTS] ForgetMeNot - Week 2: Elro CoCo and Pi Cam with OpenHAB
- [CaTS] ForgetMeNot - Week 3: Data persistence and charts with OpenHAB
- [CaTS] ForgetMeNot - Week 4: Arduino-OpenHAB communication
- [CaTS] ForgetMeNot - Week 5: Getting familiar with EAGLE
- [CaTS] ForgetMeNot - Week 6: Getting to know the TBS1052B-EDU oscilloscope
- [CaTS] ForgetMeNot - Week 7: First tests with RPiSoC
- [CaTS] ForgetMeNot - 3D Printing: EnOcean sensor bracket
- [CaTS] ForgetMeNot - 3D Printing: EnOcean rocker switch and magnet holder
- [CaTS] ForgetMeNot - 3D Printing: Food dispenser prototype
- [CaTS] ForgetMeNot - 3D Printing: Weighing scale
- [CaTS] ForgetMeNot - Security: Some basic tips
- [CaTS] ForgetMeNot - Minion: Dave, the gassy minion
Introduction
I was able to spend a little more time using the RPiSoC.
Last time, I demonstrated how I planned to control the food and water dispenser using the Python API for the RPiSoC.
Today, I ported the weighing scale, in charge of determining food and water quantity in the bowls, to the RPiSoC as well.
Circuit
During my initial tests with the weighing scale, I used the HX711 weighing module to demonstrate the functionality of the load cell. Back then, I mentioned I would ultimately move to the INA125P, based on an instructable I found, which would result in easier data collection. The mailman delivered my two INA125P today, so I got started immediately.
I drew the circuit in an earlier post, when experimenting with EAGLE. These are the connections:
In the instructable, a resistor Rg value of 10 ohms is used. I have however had beter results using values between 100 to 150 ohms, in order to cover the range of weight I need to cover (0-1kg).
Using the schematic, I breadboarded the whole thing and connected it to the RPiSoC on Port 15 Pin 4.
Python script
The code I used to read the analog value and convert it to weight is a modified version of Embedit Electronics' ADC Voltmeter.
from rpisoc import * RPiSoC('SPI') My_SAR_ADC = ADC('SAR0') #ADC value when scale is idle ScaleOffset = 2202 #Set average to offset for faster initial state CountsAverage = ScaleOffset #Analog value change per gram AdcCountPerGram = 2.89823 try: while True: My_SAR_ADC.Start() My_SAR_ADC.StartConvert() while not My_SAR_ADC.IsEndConversion(): pass Counts = My_SAR_ADC.GetResult() My_SAR_ADC.StopConvert() My_SAR_ADC.Stop() Volts = My_SAR_ADC.CountsTo_Volts(Counts) #Smoothen the readings CountsAverage = (0.9*CountsAverage) + (0.1*Counts) Grams = ((CountsAverage-ScaleOffset) / AdcCountPerGram) print('ADC OUTPUT:\t %d \nAVG OUTPUT:\t %d\nVOLTAGE:\t %.5f Volts \nWEIGHT:\t %d Grams\n' %(Counts, CountsAverage, Volts, Grams)) time.sleep(.1) except KeyboardInterrupt: RPiSoC.commChannel.cleanup()
I'll have to adapt it even more, in order to feed the data back to openHAB.
Proto shield
I moved the weighing scale circuit from breadboard to an Arduino proto shield and duplicated it for a second scale.
First, I started by soldering some headers, so I could mount the shield on the RPiSoC. I wanted to be sure this would work before soldering the rest of the circuit.
As the RPiSoC we received is still a prototype model, unexpected things could happen (remember the reversed GPIO ?).
The proto shield fitted just fine, so I proceeded with soldering the rest of the circuit.
This is the result:
The proto shield needs be extended with connections for the servo motor and digital output to control the solenoid valve.
Demo
This video was taken with the circuit still assembled on a breadboard, when testing the analog input of the RPiSoC.
You will notice a delay in determining the weight of the object. This is because some calculations are made in order to smoothen the fluctuations of the analog reading.
I'll look into a better, faster way of removing the fluctuations and ensuring a stable, correct result.
Although, in reality, there will be no such drastic value changes (I hope my cats won't gobble 500gr of food in one go ), so it's probably fine as is.
That's it for today. It's looking like I can gradually move all offloaded functionality back to the Pi using the RPiSoC. Great!