Micro Dot Phat, not displaying what is in write_string correctly


#1

Hi, So I have been working on a project involving the Micro Dot Phat and for the most part it is working well. I have it wired up with some buttons and have it set so buttons cycle through different displays: the time, IP address etc.

The issue I am having is I am trying to write the strings “D31110” and “D01115” to the display and when I press a button it alternates between them however only the last part shows up when I do this. I get the 1110 & 1115 parts but most of the first 2 LED matrices stay blank, sometimes only the last matrix lights up on each button press. I do not believe this is a wiring error because other parts of my app display the time on each matrix without any issue at all.

I did try write_char instead of write_string but that wrote a 4 instead of D on the first matrix and then the rest were just blank.

To top it all off I am a complete beginner in Python, PHP is my main language. Below is the snippet of code that deals with this part of the code, wasn’t sure of the best way to display code so hope this isn’t to bad.

alarm_obj = json.loads(alarms_string)
str_index = str(alarm_index)

time_str = alarm_obj['alarms'][str_index]['time'].replace(':','')
print("D"+alarm_obj['alarms'][str_index]['day']+time_str)
clear()
write_string("D"+alarm_obj['alarms'][str_index]['day']+time_str, kerning=False, offset_x=0)
#write_char("D")
#write_char(alarm_obj['alarms'][str_index]['day'])
#write_char('1')
#write_char('2')
#write_char('3')
#write_char('4')
show()
alarm_index += 1

if alarm_index > alarm_count:
    alarm_index = 0

This here is the afore mentioned alarms_string variable:
{“alarms”: {“0” : {“day”:“0”, “time”:“11:15”, “sound”: “1”},“1” : {“day”:“3”, “time”:“11:10”, “sound”: “2”}}}

I can provide the entire python file if needed but I don’t imagine it is pretty or efficient. I am using GPIO Zero to handle the button inputs if that is important

Any help or assistance greatly appreciated


#2

I don’t have access to a Micro Dot pHAT until next week, unfortunately.

When using write_char you must specify the offset manually, so to draw to each display it’s:

x = 0
write_char('H', offset_x=x)
x += 8  # Chars are 5 pixels wide, plus 3 virtual pixels between displays
write_char('E', offset_x=x)
x += 8
write_char('L', offset_x=x)
x += 8
write_char('L', offset_x=x)
x += 8
write_char('O', offset_x=x)
x += 8
write_char('!', offset_x=x)

Which can be simplified as:

msg = "HELLO!"
for x in range(len(msg)):
    write_char(msg[x], offset_x=x * 8)

Which is a simplified version of what write_string does.


#3

@gadgetoid - Thanks for that info, that makes sense and helped me to get write_char to work properly. Unfortunately it didn’t solve the issue. I got the string “D31110” displaying correctly but then after incrementing the alarm_index only the last two matrix were filled in with some lines from the fourth one.

That said I have been able to solve my issue. In my application I have quite a few different threads that all do different things (connecting to a server, handling button presses, setting a timer). The above code was in one of those threads but by setting the string in a variable instead of trying to write to the micro dot and then in the main loop where it handles writing to the display it uses that string and now everything works as expected.

Thanks for the assistance


#4

As yes - there’s no mutex locking in the library to gatekeep update operations, so using threads will make weird and unpredictable things happen.