Good evening,
Playing with my shiny new LCD skin, I wonder if there is a way for a script to actually check if a LCD skin is attached or not.
If it's not attached, the a class instance can be instanciated without problem and functions like .write() be called as well without error.
My motivation: After a reset, I'd like to have the pyboard check if there is a LCD and react depedinginly.
Any hints are very much apprecheated!
Greetings from Hamburg,
Ulrich
LCD connected check
Re: LCD connected check
With the LCD skin attached you should see a device with an address of 90 when you do i2c.scan():
This is actually the device for dealing with the touch buttons, but it is part of the LCD shield.
Code: Select all
>>> i2c = pyb.I2C(2, pyb.I2C.MASTER)
>>> i2c.scan()
[90]
Re: LCD connected check
Hi Dave,
Thanks a lot - once again, you helped me a lot!
I wonder if I may bother you (or another pyboard-expert) with another somewhat related issue:
- I have the LCD-skin attached in the Y-configuration
- I want the board to boot into different modes (+ do some other stuff) depending on if a button is pressed or not. For this purpose, I've added a boot.py file on the SD-card:
Now this works nicely if I use the boards reset button (which is quite hard to reach with the board in Y-position...), but does not work when I power the board up by connecting it to a power source. While the script is running nicely (LEDS work, display light is turned on etc), but the button-touch is simply ignored.
Anyone got a clue what to do?
Thanks a lot in advance
Thanks a lot - once again, you helped me a lot!
I wonder if I may bother you (or another pyboard-expert) with another somewhat related issue:
- I have the LCD-skin attached in the Y-configuration
- I want the board to boot into different modes (+ do some other stuff) depending on if a button is pressed or not. For this purpose, I've added a boot.py file on the SD-card:
Code: Select all
import pyb
pyb.LED(3).on() # indicate we are waiting for switch press
try:
import mpr121
touchbuttons = mpr121.MPR121(pyb.I2C(2, pyb.I2C.MASTER))
lcd = pyb.LCD('Y')
lcd.light(True)
except:
pass
pyb.delay(2000) # wait for user to maybe press the switch
switch_value = pyb.Switch()() # sample the switch at end of delay
pyb.LED(3).off() # indicate that we finished waiting for the switch
pyb.LED(4).on() # indicate that we are selecting the mode
try:
touchstatus = touchbuttons.touch_status()
except:
touchstatus = False
if switch_value or touchstatus:
pyb.usb_mode('CDC+HID')
lcd.write('Button was pressed \nTouch: %s'%str(touchstatus))
else:
pyb.usb_mode('CDC+MSC')
lcd.write('Touch: %s'%str(touchstatus))
pyb.LED(4).off() # indicate that we finished selecting the mode
Anyone got a clue what to do?
Thanks a lot in advance
Re: LCD connected check
Just guessing here... maybe the lcd module is not ready yet? You could try a small delay at the start of the script...
Re: LCD connected check
HI Hansel,
I had in my script a delay of 2 seconds for this reason, but it turns out that this is not sufficient.
To see how much delay I need, I've timed it:
- the switch is available pretty fast
- the buttons take more than 8(!) seconds to get reactive
Having no clue about the internals, this still seems a long time for me.
Cheers,
Ulrich
I had in my script a delay of 2 seconds for this reason, but it turns out that this is not sufficient.
To see how much delay I need, I've timed it:
Running this multiple times, I findimport pyb
pyb.LED(3).on() # indicate we are waiting for switch press
import mpr121
touchbuttons = mpr121.MPR121(pyb.I2C(2, pyb.I2C.MASTER))
lcd = pyb.LCD('Y')
lcd.light(True)
bikeboot = False
for i in range(0, 1000):
switch_value = pyb.Switch()() # sample the switch at end of delay
if switch_value:
break
touchstatus = touchbuttons.touch_status()
if touchstatus:
break
pyb.delay(10) # wait for user to maybe press the switch
pyb.LED(3).off() # indicate that we finished waiting for the switch
if switch_value or touchstatus:
lcd.write('i: %s'%str(i))
else:
lcd.write('Touch: %s'%str(touchstatus))
- the switch is available pretty fast
- the buttons take more than 8(!) seconds to get reactive
Having no clue about the internals, this still seems a long time for me.
Cheers,
Ulrich
Re: LCD connected check
I have no LCD skin, so this are only my stolen 50 cent...
The datasheet of the touch sensing chip tells something about long duration for the baseline calibration of the touch sensing electrode. It can initially take some time to enter "run mode" for the touch sensing electrodes. See page 16 and especially the last paragraph.
http://micropython.org/resources/datasheets/MPR121.pdf
I'd suggest to play around with the upper two bits of the register (CL field, bits 6 and 7) when initializing the LCD touch sensors on the I²C bus. The examples do use the default value which needs some time for the baseline calibration. Those can be preset with vaules from some touch sensor values on startup.
The datasheet of the touch sensing chip tells something about long duration for the baseline calibration of the touch sensing electrode. It can initially take some time to enter "run mode" for the touch sensing electrodes. See page 16 and especially the last paragraph.
http://micropython.org/resources/datasheets/MPR121.pdf
I'd suggest to play around with the upper two bits of the register (CL field, bits 6 and 7) when initializing the LCD touch sensors on the I²C bus. The examples do use the default value which needs some time for the baseline calibration. Those can be preset with vaules from some touch sensor values on startup.
Re: LCD connected check
Good evening,
Thanks for the hint - your post confirms me that I'm not simply making a stupid mistake. Unfortunately I'm not fit enough to play around and follow up your comments - That's why the pyboard is so attractive for me - being able to use my normal python knowlege and being able to program a micro-controller! But one day, I'll hopefully find the time to learn it. Till then I'll simply wait 9 seconds.
Cheers,
Ulrich
Thanks for the hint - your post confirms me that I'm not simply making a stupid mistake. Unfortunately I'm not fit enough to play around and follow up your comments - That's why the pyboard is so attractive for me - being able to use my normal python knowlege and being able to program a micro-controller! But one day, I'll hopefully find the time to learn it. Till then I'll simply wait 9 seconds.
Cheers,
Ulrich