Adafruit DC and Stepper Motor HAT

MatAff
MatAff New Member Posts: 18 ✭✭

I'm trying to use the Up Board with the Adafruit DC and Stepper Motor HAT. I've installed Ubuntu and updated the Kernel as described here: https://wiki.up-community.org/Ubuntu and also installed: sudo apt install upboard-extras, and gave my user (up) i2c permissions using sudo usermod -a -G i2c up

I then tried to follow install the HAT software using the instructions I found here: https://wiki.up-community.org/Adafruit#Using_Adafruit_DC_.26_Stepper_Motor_HAT_on_UP However it appears that the repository https://github.com/emutex/Adafruit-Motor-HAT-Python-Library.git doesn't exist anymore.

But after some digging I found this repository https://github.com/emutex/Adafruit_Python_GPIO which states: "This version of adafruit python gpio add support for all the mraa library to use adafruit shields. The only thing needed is to double check the i2c/spi bus number for the given board. First install this library from this repository with: sudo python setup.py install then install the others adafruit libraries, they should work out of the box.

So first I installed https://github.com/intel-iot-devkit/mraa using
sudo add-apt-repository ppa:mraa/mraa
sudo apt-get update
sudo apt-get install libmraa2 libmraa-dev libmraa-java python-mraa python3-mraa node-mraa mraa-tools

Then I installed: https://github.com/emutex/Adafruit_Python_GPIO but I was not sure how to double check the i2c/spi bus number. Finally, I installed the Adafruit software using https://learn.adafruit.com/adafruit-dc-and-stepper-motor-hat-for-raspberry-pi/installing-software

When I run the examples/DCTest.py I get the error message: IOError: [Errno 6] No such device or address (see full error below.) Presumably I need to do something related to the default I2C bus. Any suggestions on how to proceed?

Thanks!
Mat

Traceback (most recent call last):
File "DCTest.py", line 8, in
mh = Adafruit_MotorHAT(addr=0x60)
File "build/bdist.linux-x86_64/egg/Adafruit_MotorHAT/Adafruit_MotorHAT_Motors.py", line 231, in init
File "build/bdist.linux-x86_64/egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py", line 59, in init
File "build/bdist.linux-x86_64/egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py", line 95, in setAllPWM
File "build/bdist.linux-x86_64/egg/Adafruit_GPIO/I2C.py", line 118, in write8
File "build/bdist.linux-x86_64/egg/Adafruit_PureIO/smbus.py", line 256, in write_byte_data
IOError: [Errno 6] No such device or address

Tagged:

Comments

  • eduncan911
    eduncan911 Administrator, Moderator Posts: 157 admin
    edited September 2018

    @MatAff Hello! On Rasbian RPi installs, there is an i2cdetect tool that can be used to probe the i2c bus for what addresses are on the bus. Though, I don't know off hand how to do that on Intel-based Linux.

    Try searching for i2c in aptitude to see if there are tools in the public repos for x86/amd64:

    sudo apt-cache search i2c
    

    Eric Duncan - UP Evangelist - My thoughts are of my own free will

    Answered? Please remember to mark the posted answered to highlight it for future visitors!

  • MatAff
    MatAff New Member Posts: 18 ✭✭
    edited October 2018

    @eduncan911 Thanks for the suggestion!

    Since my last post I tried a number of things. Firstly, I made sure the HAT was working properly on a Raspberry Pi, which it was! On the Pi I also ran:

    sudo i2cdetect -y 1

    Which gave the following output.

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    70: 70 -- -- -- -- -- -- --   
    

    This tell me a I2C device is being detected on channel/port/bus 1 and with addresses 60 and 70. Next, I put the HAT back on the UP board and ran:

    sudo i2cdetect -y -r 0

    Which gave:

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    70: -- -- -- -- -- -- -- --     
    

    This show no I2C are being detected. I tried different channels/ports, with the same result. I also ran the following, which seems to indicate I2C is enabled?

    $ sudo i2cdetect -F 0
    Functionalities implemented by /dev/i2c-0:
    I2C yes
    SMBus Quick Command yes
    SMBus Send Byte yes
    SMBus Receive Byte yes
    SMBus Write Byte yes
    SMBus Read Byte yes
    SMBus Write Word yes
    SMBus Read Word yes
    SMBus Process Call yes
    SMBus Block Write yes
    SMBus Block Read yes
    SMBus Block Process Call yes
    SMBus PEC yes
    I2C Block Write yes
    I2C Block Read yes

    To me all this suggests, that I have enabled I2C, but somehow the board is not being detected.

    Any thoughts or suggestions on what to try next would be be greatly appreciated!

    Thanks!
    Mat

  • eduncan911
    eduncan911 Administrator, Moderator Posts: 157 admin
    edited October 2018

    @MatAff said:
    @eduncan911 Thanks for the suggestion!

    Since my last post I tried a number of things. Firstly, I made sure the HAT was working properly on a Raspberry Pi, which it was! On the Pi I also ran:

    sudo i2cdetect -y 1

    Which gave the following output.

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    

    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: 70 -- -- -- -- -- -- --

    This tell me a I2C device is being detected on channel/port/bus 1 and with addresses 60 and 70. Next, I put the HAT back on the UP board and ran:

    sudo i2cdetect -y -r 0

    Which gave:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    

    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --

    This show no I2C are being detected. I tried different channels/ports, with the same result. I also ran the following, which seems to indicate I2C is enabled?

    sudo i2cdetect -F 0

    Functionalities implemented by /dev/i2c-0:
    I2C yes
    SMBus Quick Command yes
    SMBus Send Byte yes
    SMBus Receive Byte yes
    SMBus Write Byte yes
    SMBus Read Byte yes
    SMBus Write Word yes
    SMBus Read Word yes
    SMBus Process Call yes
    SMBus Block Write yes
    SMBus Block Read yes
    SMBus Block Process Call yes
    SMBus PEC yes
    I2C Block Write yes
    I2C Block Read yes

    To me all this suggests, that I have enabled I2C, but somehow the board is not being detected.

    Any thoughts or suggestions on what to try next would be be greatly appreciated!

    Thanks!
    Mat

    Can you snap some photos of your bios settings for the GPIO? You'll have to page down and take pics of multiple screens.

    It may just be a BIOS tweak.

    Eric Duncan - UP Evangelist - My thoughts are of my own free will

    Answered? Please remember to mark the posted answered to highlight it for future visitors!

  • MatAff
    MatAff New Member Posts: 18 ✭✭

    Is this the correct screen? I did not find multiple screens to take pictures of.

  • MatAff
    MatAff New Member Posts: 18 ✭✭
    edited October 2018

    I played with the settings shown in my previous comment, changing:
    I2CO/GPIO selection from GPIO to I2CO
    I2S/GPIO Selection from GPIO to I2S

    For a moment I was excited when two addresses showed up (see below), however it turned out these were related to whether the monitor and keyboard/mouse. When I switched back to SSH these disappeared.

    Any thoughts and suggestions would be extremely appreciated! :)

    sudo i2cdetect -y 2
    
    [sudo] password for up: 
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- 3a -- -- -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    70: -- -- -- -- -- -- -- --     
    
  • eduncan911
    eduncan911 Administrator, Moderator Posts: 157 admin
    edited October 2018

    Hello @MatAff !

    You are on the right path. I seem to remember some combination of HAT settings to get I2C working. You need to make those changes in the screenshot to I2C0/GPIO to be the value of "I2C0" to enable functionality at the least, yes.

    Try setting I2S to Disabled for now.

    Also, try going through top options for LPSS and SCC and disabling all of them. Then perhaps try to enable just the LPSS I2C #1 Support, and then maybe #2 Support. Iterate through these settings as well.

    Also, try to list your i2c ports during these iterations of BIOS settings:

    sudo -i
    for i in `seq 0 6`; do echo Bus i2c-$i - name: `cat i2c-$i/name`; done
    

    You'll need root access to do all of the above. Hence, the sudo -i.

    That may start to give us a clue.

    Also, could you post the output of this command?

    uname -a
    

    I'll try to wrap up my Windows tests this weekend and be free next week for Linux.

    Eric Duncan - UP Evangelist - My thoughts are of my own free will

    Answered? Please remember to mark the posted answered to highlight it for future visitors!

  • MatAff
    MatAff New Member Posts: 18 ✭✭

    Hey @eduncan911 Thank you for your suggestions!

    I ran:

    uname -a

    which produced:

    Linux up-UP-CHT01 4.10.0-42-generic #5000~upboard11-Ubuntu SMP Mon Jun 25 15:58:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

    Next I tried various BIOS settings like you suggested unfortunately no luck (I checked all channels using sudo i2cdetect -y [channel])

    I also ran

    root@up-UP-CHT01:~# for i in seq 0 6; do echo Bus i2c-$i - name: cat i2c-$i/name; done

    Which produced

    cat: i2c-0/name: No such file or directory
    Bus i2c-0 - name:
    cat: i2c-1/name: No such file or directory
    Bus i2c-1 - name:
    cat: i2c-2/name: No such file or directory
    Bus i2c-2 - name:
    cat: i2c-3/name: No such file or directory
    Bus i2c-3 - name:
    cat: i2c-4/name: No such file or directory
    Bus i2c-4 - name:
    cat: i2c-5/name: No such file or directory
    Bus i2c-5 - name:
    cat: i2c-6/name: No such file or directory
    Bus i2c-6 - name:

    Thanks!
    Mat

  • MatAff
    MatAff New Member Posts: 18 ✭✭

    With help from my friend Sky, I finally got this working! Below the steps we followed! First, we tested if the GPIO pins were working, by writing a small Python script to switch them on and off and checked them using a volt meter. Using this script we made sure the GPIO pins used by I2C were working (they were).

    Next we installed ubilinux. This may not have been necessary and I may switch back to Ubuntu at a later point, but that's what I currently have installed.

    We went into the BIOS and changed some more settings. Under South bridge we switched ACPI to PCI. Like installing unilinux this may not have been necessary.

    Next, we used i2cdetect using a different option. Please note do not use this option without first researching it properly! Apparently it can harm some hardware. We didn't realize this until after we had run it and got lucky I guess. But we ran: sudo i2cdetect -y -r 1 (adding the -r). This uses a different process the query the addresses, and with this, the HAT showed up! So possibly the HAT was there all along, but not being found without the -r option. This in line with other posts I have read where devices may not show using i2cdetect even though they can be used.

    Next I cloned the Adafruit HAT library and installed it. Running DCTest.py gave an error related to Adafruit_GPIO. This was because the default bus is not specified for the UP board in Adafruit_GPIO. I cloned the Adafruit_GPIO library. In the I2C.py file in the method get_default_bus I replace the error message with return 1. I installed the Adafruit_GPIO library. After this I ran the DCTest.py program again and the wheels (attached to the HAT) started spinning!

    Apologies if I've missed any details. Hopefully some of the info in here will help folks in future! And thanks for all help received!

Tagged