0

I was setting up a joystick using this tutorial. When I ran

import RPi.GPIO as GPIO
import smbus
import time

address = 0x48
bus = smbus.SMBus(1)
cmd = 0x40
Z_Pin = 12

def analogRead(chn):
    value = bus.read_byte(address)
    return value
    
def analogWrite(value):
    bus.write_byte_data(address,cmd,value)  

def setup():
    GPIO.setmode(GPIO.BOARD)        
    GPIO.setup(Z_Pin,GPIO.IN,GPIO.PUD_UP)

def loop():
    while True:     
        val_Z = GPIO.input(Z_Pin)
        val_Y = analogRead(0)
        val_X = analogRead(1)
        print ('value_X: %d ,\tvlue_Y: %d ,\tvalue_Z: %d'%(val_X,val_Y,val_Z))
        time.sleep(0.01)

def destroy():
    bus.close()
    GPIO.cleanup()

if __name__ == '__main__':
    print ('Program is starting ... ')
    setup()
    try:
        loop()
    except KeyboardInterrupt:
        destroy()

I get this as the output

Program is starting ...
Traceback (most recent call last):
  File "main.py", line 37, in <module>
    loop()
  File "main.py", line 24, in loop
    val_Y = analogRead(0)
  File "main.py", line 10, in analogRead
    value = bus.read_byte(address)
OSError: [Errno 5] Input/output error

I tried my best to take to have a good image of my wiring My Wiring

  • 2
    Code? Wiring? Picture? – Unsigned_Arduino Oct 27 at 22:12
  • 1
    We need to know what you have wired up. Not what you should have wired up. – joan Oct 28 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.