9acca9
Posts: 13
Joined: Sun Sep 18, 2016 11:20 pm

Is this right? (accomodating a code)

Sun Sep 01, 2019 11:21 pm

Hi.
Im trying to acommodate a code.
The problem is that a code creator use a lcd display with buttons, and i dont have that.
So, im gonna use a mcp23017 to attach the buttons (i prefer this instead of use the gpio of the raspberry).

This, for example is part of the problem

Code: Select all

# Make list of button value, text, and backlight color.
buttons = ( (LCD.SELECT, 'Shutdown', (1,1,1)),  # Select
            (LCD.LEFT,   'No'  , (1,0,0)),    # Left
            (LCD.UP,     'Yes'    , (0,0,1)),  # Up
            (LCD.DOWN,   'No'  , (0,1,0)),   # Down
            (LCD.RIGHT,  'No' , (1,0,1)) )  # Right
So i think, made my buttons with this kind of code:

Code: Select all

from IOPi import IOPi
import time

bus = IOPi(0x20)
bus.set_pin_direction(1, 1)  # set pin 1 as an input
bus.set_pin_pullup(1, 1)  # enable the internal pull-up resistor on pin 1
bus.invert_pin(1, 1)  # invert pin 1 so a button press will register as 1
LEFT = str(CERO)

while True:
    if bus.read_pin(1) == 1:  # check to see if the button is pressed
        LEFT = "No"
        time.sleep(2)  # wait 2 seconds
    else:
        LEFT = "CERO"  # turn to 0 the variable, so is not allways saying "no"
So i will change the buttons to this:

Code: Select all

buttons = (LEFT, RIGHT, SELECT, UP, DOWN, RIGHT)
            
This is good?? This will work??

ps.: this is the all code if somebody want to see
https://github.com/mdobres/maxnox/blob/master/maxnox.py

ps: looking a little more, i see that in adafruit charlcd library there is this info

Code: Select all

# Char LCD plate button names.
SELECT                  = 0
RIGHT                   = 1
DOWN                    = 2
UP                      = 3
LEFT                    = 4
So, probably i dont have tu put "no", for LEFT, i think is "4" (integer)

User avatar
MrYsLab
Posts: 375
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Is this right? (accomodating a code)

Mon Sep 02, 2019 2:31 pm

With just partial snippets of code, it is difficult to understand what your code actually does. Electing to use an i2c device for digital input instead of using simple GPIO input adds several levels of complexity to your code. If you really need to use mcp23017, take a look at this link: mcp23017

9acca9
Posts: 13
Joined: Sun Sep 18, 2016 11:20 pm

Re: Is this right? (accomodating a code)

Mon Sep 02, 2019 9:11 pm

Hi, thanks!
This is the code that give me problems, because i dont have the "sainsmart LCD Display with buttons"..... buttons, thats my problem. And i want to attach them in the best way to not change the original code.
This : https://github.com/mdobres/maxnox/blob/master/maxnox.py

User avatar
MrYsLab
Posts: 375
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Is this right? (accomodating a code)

Mon Sep 02, 2019 10:26 pm

Sorry, but I gave you a bad link. Here is the correct link: https://learn.adafruit.com/using-mcp23 ... usage-2-12

The Adafruit library being used by the maxnox file seems to have been deprecated. https://github.com/adafruit/Adafruit_Python_CharLCD

Do the buttons work at all? If not, you might want to verify the i2c address you are using for the mcp23017.

Return to “Python”