thieled Geschrieben January 26, 2015 at 02:35 Geschrieben January 26, 2015 at 02:35 A very new python programmer here who has built the Tinkerforge weather station connected to a Raspberry Pi. I am starting to tinker with the Tinkerforge code and want to implement the is_backlight_on function for the LCD. I more often than not get a timeout error when I call this function; sometimes it works but mostly not. Any help would be appreciated for a newbie! Zitieren
borg Geschrieben January 26, 2015 at 11:45 Geschrieben January 26, 2015 at 11:45 Can you post the source code that has this behavior? Zitieren
thieled Geschrieben January 27, 2015 at 10:20 Autor Geschrieben January 27, 2015 at 10:20 Here's the code ... #!/usr/bin/env python # -*- coding: utf -8 -*- HOST="localhost" PORT=4223 UID="ogH" import time; from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_lcd_20x4 import LCD20x4 # Callback functions for button status def cb_pressed(i): print('Pressed: '+ str(i)) BacklightON = lcd.is_backlight_on() print(BacklightON) if __name__ == "__main__": ipcon=IPConnection() # Create IP connection lcd=LCD20x4(UID,ipcon) # Create device object ipcon.connect(HOST,PORT) # Connect to brickd # Don't use device before ipcon is connected # Register button status callback to cb_pressed lcd.register_callback(lcd.CALLBACK_BUTTON_PRESSED,cb_pressed) # lcd.backlight_off() BacklightON = lcd.is_backlight_on() print(BacklightON) while True: n=0 # Line 0 Line="Button 0: MAIN MENU" # Determine start position to be centred # Position=(20-len(Line))/2 Position=0 # Write Line 0 lcd.write_line(0,Position,Line) # Line 1 Line="Button 1: DATE/TIME" # Determine start position to be centred # Position=(20-len(Line))/2 # Write Line 1 lcd.write_line(1,Position,Line) # Line 2 Line="Button 2: WEATHER" # Determine start position to be centred # Position=(20-len(Line))/2 # Write Line 2 lcd.write_line(2,Position,Line) and here's the error message ... >>> False Pressed: 0 Exception in thread Callback-Processor: Traceback (most recent call last): File "/home/pi/weather_station/tinkerforge/ip_connection.py", line 938, in send_request response = device.response_queue.get(True, self.timeout) File "/usr/lib/python3.2/queue.py", line 193, in get raise Empty queue.Empty During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner self.run() File "/usr/lib/python3.2/threading.py", line 693, in run self._target(*self._args, **self._kwargs) File "/home/pi/weather_station/tinkerforge/ip_connection.py", line 812, in callback_loop self.dispatch_packet(data) File "/home/pi/weather_station/tinkerforge/ip_connection.py", line 793, in dispatch_packet cb(self.deserialize_data(payload, form)) File "/home/pi/weather_station/test_lcd.py", line 17, in cb_pressed BacklightON = lcd.is_backlight_on() File "/home/pi/weather_station/tinkerforge/bricklet_lcd_20x4.py", line 123, in is_backlight_on return self.ipcon.send_request(self, BrickletLCD20x4.FUNCTION_IS_BACKLIGHT_ON, (), '', '?') File "/home/pi/weather_station/tinkerforge/ip_connection.py", line 947, in send_request raise Error(Error.TIMEOUT, msg) tinkerforge.ip_connection.Error: -1: Did not receive response for function 5 in time Many thanks borg. Zitieren
borg Geschrieben January 27, 2015 at 17:35 Geschrieben January 27, 2015 at 17:35 Your problem is that the code in your while loop runs as fast as it can. This will fill up all of the buffers and it is not possible for the callbacks to come through anymore. Try to add a small sleep at the end of the while loop, like this: while True: n=0 # Line 0 Line="Button 0: MAIN MENU" # Determine start position to be centred # Position=(20-len(Line))/2 Position=0 # Write Line 0 lcd.write_line(0,Position,Line) # Line 1 Line="Button 1: DATE/TIME" # Determine start position to be centred # Position=(20-len(Line))/2 # Write Line 1 lcd.write_line(1,Position,Line) # Line 2 Line="Button 2: WEATHER" # Determine start position to be centred # Position=(20-len(Line))/2 # Write Line 2 lcd.write_line(2,Position,Line) time.sleep(0.1) Zitieren
thieled Geschrieben January 28, 2015 at 09:49 Autor Geschrieben January 28, 2015 at 09:49 Problem solved - many thanks borg! Zitieren
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.