Unsigned char array from int array in python

I am trying to identify a new character (capital German umlaut "Ä") on my 2004 lcd on raspberry pi using wiringPi 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 the 'lcdCharDef' method, argument 3 of type 'unsigned char [8]'

I expected these ints be the same as unsigned chars

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

How can I convert an array to a type that can be accepted?

PS (Note that (as I understand it) the python wiringPi library just wraps the C wiring functions of Pi)

[edit]
I opened the github question: https://github.com/WiringPi/WiringPi2-Python/issues/20

+4
source share
1 answer

I did a little research and found the source of the corresponding python binding in this github registry .

Matching line

 res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_unsigned_char, 0 | 0 ); 

as you can see, you need to pass the equivalent of a python pointer to an unsigned char. According to this stream , the equivalent is a byte string. This means that the right call will be

 import struct wiringpi.lcdCharDef(lcd_handle, 0, struct.pack('8B', *cap_umlaut_a)) 

which should be equivalent

 wiringpi.lcdCharDef(lcd_handle, 0, b'\x0A\x04\x0A\x11\x1F\x11\x11\x00') 
+1
source

All Articles