File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -133,11 +133,11 @@ def get_scale_data(self):
133
133
the_byte |= bits [byte_n * 8 + bit_n ]
134
134
data_bytes [byte_n ] = the_byte
135
135
# do some very basic data checking
136
- if data_bytes [0 ] != 3 or data_bytes [1 ] != 3 or data_bytes [ 7 ] != 4 :
136
+ if data_bytes [0 ] != 3 and data_bytes [0 ] != 2 : # check the MSB (differs between DYMO scale models)
137
137
raise RuntimeError ("Bad data capture" )
138
-
139
- if data_bytes [ 8 ] != 0x1C or data_bytes [ 9 ] != 0 or data_bytes [ 10 ] \
140
- or data_bytes [11 ] != 0 :
138
+ if data_bytes [ 1 ] != 3 or data_bytes [ 7 ] != 4 or data_bytes [ 8 ] != 0x1C :
139
+ raise RuntimeError ( "Bad data capture" )
140
+ if data_bytes [ 9 ] != 0 or data_bytes [ 10 ] or data_bytes [11 ] != 0 :
141
141
raise RuntimeError ("Bad data capture" )
142
142
reading = ScaleReading ()
143
143
# parse out the data_bytes
Original file line number Diff line number Diff line change
1
+ import time
1
2
import board
2
3
import digitalio
3
4
import adafruit_dymoscale
7
8
units_pin .switch_to_output ()
8
9
dymo = adafruit_dymoscale .DYMOScale (board .D4 , units_pin )
9
10
11
+ # take a reading of the current time
12
+ time_stamp = time .monotonic ()
13
+
10
14
while True :
11
15
reading = dymo .weight
12
16
text = "{} g" .format (reading .weight )
13
17
print (text )
14
- # to avoid sleep mode, we'll toggle the units pin.
15
- # if we don't want to switch the units on the next read...
16
- dymo . toggle_unit_button ( )
17
-
18
- # if we do want to switch the units on the next read...
19
- # dymo.toggle_unit_button(switch_units=True )
18
+ # to avoid sleep mode, toggle the units pin every 2 mins .
19
+ if ( time . monotonic () - time_stamp ) > 120 :
20
+ print ( 'toggling units button...' )
21
+ dymo . toggle_unit_button ()
22
+ # reset the time
23
+ time_stamp = time . monotonic ( )
You can’t perform that action at this time.
0 commit comments