ASCII ;-)
https://www.rapidtables.com/code/text/ascii-table.html
Incrementing a count, getting interpreted after 8?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- neradoc
- Posts: 542
- Joined: Wed Apr 27, 2016 2:38 pm
- xanatos
- Posts: 110
- Joined: Thu Jun 18, 2009 3:09 pm
Re: Incrementing a count, getting interpreted after 8?
I am truly grateful for all the help you've given me, but I feel I'm taking up far too much of your attention. I'm going to give this one last go...
I have this code that gets the time/date from a DS3231 RTC:
It works like a champ. Outputs MO 2022/01/30 19:22:34
If I send this hard-coded hex to the display (for the hours digits):
It displays the correct decimal number "19" correctly in the proper location.
If I have a variable (hrs) that is derived from the DS3231 (t.tm_hour [which prints as "19" when printed raw]) that I've hexlified and unhexlified lol, that - when printed to REPL - shows up as b'13', and if I replace the hard-coded b'\x13' with that variable, I get a "48" in the hours display.
I have tried hex(t.tm_hour), bytes(t.tm_hour), every version of hexlify and unhexlify I can, and received every error possible about converting, needing bytes or bytes-like objects, and every combination of the above mixed together. I feel like when I am trying to teach my granddaughter simple division and she just blurts out a random number LOL! I do not know why I cannot wrap my head around this one, tiny little issue. I'm hoping you will see where my utter blind spot is here, and I truly apologize for needing to ask yet again...
UPDATE:
Still at it. Tried:
Got:
Tried converting to str, hex, bytes(t.tm_hour).encode().... literally just throwing stuff out to see what sticks at this point... So far have tried over a dozen permutations of binascii.hexlify...
I have this code that gets the time/date from a DS3231 RTC:
Code: Select all
t = ds3231.datetime
DateText = "{} {}/{:02}/{:02}".format(days[int(t.tm_wday)], t.tm_year, t.tm_mon, t.tm_mday)
TimeText = "{}:{:02}:{:02}".format(t.tm_hour, t.tm_min, t.tm_sec)
text_time = DateText + " " + TimeText
print(text_time)
print(t.tm_hour, t.tm_min, t.tm_sec)
If I send this hard-coded hex to the display (for the hours digits):
Code: Select all
D1 = b"\x24\x00\x02\x05\x0E\x00" + b'\x13' + b'\x00'
If I have a variable (hrs) that is derived from the DS3231 (t.tm_hour [which prints as "19" when printed raw]) that I've hexlified and unhexlified lol, that - when printed to REPL - shows up as b'13', and if I replace the hard-coded b'\x13' with that variable, I get a "48" in the hours display.
Code: Select all
D1 = b"\x24\x00\x02\x05\x0E\x00" + hrs + b'\x00'
UPDATE:
Still at it. Tried:
Code: Select all
D1 = b"\x24\x00\x02\x05\x0E\x00" + t.tm_hour.encode() + b'\x00'
Code: Select all
AttributeError: 'int' object has no attribute 'encode'
- neradoc
- Posts: 542
- Joined: Wed Apr 27, 2016 2:38 pm
Re: Incrementing a count, getting interpreted after 8?
bytes(19) creates a bytes array of 19 bytes all equal to 0.
bytes([19]) converts the list [19] into a bytes array, provided each number in the list is between 0 and 255.
so here is 2 ways:
bytes([19]) converts the list [19] into a bytes array, provided each number in the list is between 0 and 255.
so here is 2 ways:
Code: Select all
>>> hrs = 19
>>> bytes([hrs])
b'\x13'
>>> hrs.to_bytes(1,"big")
b'\x13'
Code: Select all
D1 = b"\x24\x00\x02\x05\x0E\x00" + bytes([hrs]) + b'\x00'
- xanatos
- Posts: 110
- Joined: Thu Jun 18, 2009 3:09 pm
Re: Incrementing a count, getting interpreted after 8?
I am truly indebted to you for your help. I wish there was some way I could reciprocate. I still have more questions, but I cannot in good conscience take up more of your time :)
Thanks very much for helping so much on my issues here. You've made a huge difference.
Dave
Thanks very much for helping so much on my issues here. You've made a huge difference.
Dave
Please be positive and constructive with your questions and comments.