# Micro Dot Phat, not displaying what is in write\_string correctly

**URL:** <https://forums.pimoroni.com/t/micro-dot-phat-not-displaying-what-is-in-write-string-correctly/8966>\
**Category:** Support\
**Created:** [October 23, 2018, 8:47pm UTC](https://forums.pimoroni.com/t/micro-dot-phat-not-displaying-what-is-in-write-string-correctly/8966 "2018-10-23T20:47:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pythwoz](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@pythwoz](https://forums.pimoroni.com/u/pythwoz)\
**Post date:** [October 23, 2018, 8:47pm UTC](https://forums.pimoroni.com/t/micro-dot-phat-not-displaying-what-is-in-write-string-correctly/8966/1 "2018-10-23T20:47:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [October 25, 2018, 8:55am UTC](https://forums.pimoroni.com/t/micro-dot-phat-not-displaying-what-is-in-write-string-correctly/8966/2 "2018-10-25T08:55:51Z")

</div>

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![pythwoz](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@pythwoz](https://forums.pimoroni.com/u/pythwoz)\
**Post date:** [October 26, 2018, 1:36pm UTC](https://forums.pimoroni.com/t/micro-dot-phat-not-displaying-what-is-in-write-string-correctly/8966/3 "2018-10-26T13:36:17Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [October 26, 2018, 4:20pm UTC](https://forums.pimoroni.com/t/micro-dot-phat-not-displaying-what-is-in-write-string-correctly/8966/4 "2018-10-26T16:20:00Z")

</div>

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