Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

unsigned char array from int array in python

I try to define a new character (a capital german umlaut "Ä") on my 2004 lcd on a raspberry pi using wiringPi's lcdCharDef()

This is my code

import wiringpi2 as wiringpi
# Ä
cap_umlaut_a = [
 int('0b01010', 2),
 int('0b00100', 2),
 int('0b01010', 2),
 int('0b10001', 2),
 int('0b11111', 2),
 int('0b10001', 2),
 int('0b10001', 2),
 int('0b00000', 2)
]
print(cap_umlaut_a) # [10, 4, 10, 17, 31, 17, 17, 0]
wiringpi.lcdCharDef(lcd_handle, 0, cap_umlaut_a)

When I run this code I get the following error:

TypeError: in method 'lcdCharDef', argument 3 of type 'unsigned char [8]'

I expected these ints to be the same as unsigned chars

[edit]
In a different part of the code I use ord(char) to convert only one character to an unsigned int. Can this lead to the correct anser?

How can I cast/convert the array to a type that can be accepted?

P.S. (Note that (as far as I understand it) the python wiringPi library simply wraps the C functions of wiringPi)

[edit]
I opened an issue on github: https://github.com/WiringPi/WiringPi2-Python/issues/20

Answer*

Draft saved
Draft discarded
Cancel
7
  • Thank you for the answer. I really appreciate that! I just tried it. wiringpi.lcdCharDef(self.lcd_handle, 0, b'\x0A\x04\x0A\x11\x1F\x11\x11\x0') gives an error "ValueError: invalid \x escape" and wiringpi.lcdCharDef(lcd_handle, 0, struct.pack('8B', *cap_umlaut_a)) gives "struct.error: pack requires exactly 8 arguments" Commented Jul 29, 2015 at 23:42
  • 1
    I fixed the first error, but I can't reproduce the second one (with the definitions from your question) Commented Jul 29, 2015 at 23:45
  • hm. thanks for fixing the first one - I've seen it myself now :) now I also get the TypeError here... Maybe there is something else wrong in my code. I will try to make a running minimal example tomorrow and either post it or accept your answer, if I can locate the mistake. Commented Jul 29, 2015 at 23:50
  • ... well, who needs sleep anyway. I just created the minimal example. Still get the same error. You can find it here: gist.github.com/anonymous/0fd82d376cd22763faf1 Commented Jul 29, 2015 at 23:58
  • @speendo, can you try with a normal string instead of a byte string? :< Commented Jul 30, 2015 at 0:24

default

AltStyle によって変換されたページ (->オリジナル) /