Raspberry Pi Implementation
Vanlon opened this issue · 1 comments
Vanlon commented
Is there any documentation on this on how to use it on a R Pi? I can get the serial output, but how do you access the menu. Possibly some example Python scripts.
circuitmike commented
I use one of these with a Raspberry Pi. The easiest way I found to do it was to use the pexpect library. For example, here's a snippet of code where I use pexpect to tare the scale:
def tare(self):
logging.debug('tare')
self.lastTare = int(time.time())
px = pexpect.fdpexpect.fdspawn(self.serialObject)
px.expect('\n[-.\d]+,[a-z]+,[-.\d]+')
px.send('x')
px.expect('\n>')
px.send('1')
px.expect('Tare point 1: [-\d]+')
px.expect('Tare point 2: [-\d]+')
px.expect('\n>')
px.send('x')
i = px.expect(['\n[-.\d]+,[a-z]+,[-.\d]+', '\n>'])
if i == 1:
logging.debug('Stupid bug encountered - sending another x')
px.send('x')
px.expect('\n[-.\d]+,[a-z]+,[-.\d]+')
logging.debug('Extra-x hack appears to have worked')
The "extra X hack" at the end there is because I'm using an old version of the OpenScale firmware that has a bug where sometimes hitting "x" at the menu doesn't exit, but just re-displays the menu, and you need to hit "x" again for it to actually exit. I should really update the firmware at some point...