How to control servo on Udoo x86 in python

Discussion in 'UDOO X86' started by pierro, Apr 12, 2019.

  1. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    Hi, I have an udoo x86 Ultra card where I installed Ubuntu.

    I installed python and managed to create a program to display the video from my stereo card.
    However despite my many researches and my grove kit I still do not know how to make a program that controls my servo motor.

    Thank you in advance for your advice.
     
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    evaloverde likes this.
  3. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
  4. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    So it was enough for me to program my servomotors in the same way that they are programmed on arduino, using the same libraries.
     
    waltervl likes this.
  5. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    In fact despite my research and my attempts I still have not managed to run a single servomotor.
    Do you have a tutorial to manage them in python? Thank you
     
  6. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
  7. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    I have tried many ways the code in python. The command window opens but nothing works. Yet I read a lot of pages about Udoo to find a solution.
     
  8. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    This is nothing special Udoo stuff. This is exactly the same as a PC (or Raspberry Pi) communicate with an Arduino. The only thing you have to know is the name of the serial port on Linux side that is communicating with the Arduino 101 (Curie).
    You have to be sure that only 1 program is communicating. So not also have Arduino serial monitor and your python program open. If python has no response you have to debug python an so better use a python oriented page instead of Udoo.
     
  9. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    Thank you but my servomotor is connected to pin 9, pin RND and pin 5V.
    How do I translate that so that it can work under linux?
    Should not you install a driver?
     
  10. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    The Udoo X86 is a computer and an Arduino on 1 board. They communicate with a fixed USB connection. It is like a raspberry pi and an Arduino. So your servo you have to connect with the Arduino part and program it with the Arduino IDE you have to install on the Linux side of the Udoo. Then you use python to send commands through serial (eg rotate 90 degrees) to the Arduino. It will rotate the servo. The last link I gave you was an example how to do this but an an raspberry/Arduino combination. So you have to adapt it a little to use it on your Udoo. Most likely you only have to change the serial port address in your python program.
     
  11. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    I am completely lost on this subject. I did not think it was so difficult to program that.
    If I ever do that I'll make a video that I post on my YouTube channel to show others how to do it.
     
  12. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    So I can not program this in python outside the arduino IDE?
    Because I program in python exclusively in console mode.
     
  13. ccs_hello

    ccs_hello UDOOer

    Joined:
    Apr 15, 2017
    Messages:
    536
    Likes Received:
    194
    https://arduino.stackexchange.com/questions/105/programming-an-arduino-using-python-rather-than-c-c

    Another approach (two computer approach: PC + MCU) is to get Arduino to run firmata, i.e., make itself as a slave being indirectly controlled by the PC (the UDOO x86),
    then get the PC (running Python and others) to "drive" the slave.

    Remember that Arduino, after all, is just running on a tiny MCU (microcontroller) with a rich I/O capability but not a lot of brain; while a PC (UDOO x86's main Intel CPU) is a rather powerful computer with a lot of programming language to support but just a limited I/O capability.
    UDOO x86 board is a happy marriage between the two and why not take advantage of both.
     
  14. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    Ok thank you for your advice, but I am talented only in web and database. In the programmable cards the only thing I know how to do is the installation of linux and python programming with some notions of electronics.
     
  15. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    I tried to make a simple code to light a led with firmata, but I did not manage to light it

    import pyfirmata

    board = pyfirmata.Arduino('/dev/ttyACM0')

    board.digital[7].write(1)
    board.pass_time(1)
    board.digital[7].write(0)
    board.pass_time(1)
    board.digital[7].write(1)
    board.pass_time(1)
    board.exit()
     
  16. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Is your Arduino side working at all. Can you compile and send the Arduino Blink sketch example to the Arduino with the Arduino IDE? This should result in a blinking green led on your Udoo X86. After that send the firmata sketch to your arduino and try again to communicate with Python (pyfirmata)
     
  17. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    I have to use the arduino IDE?
    I used it a long time ago when I only worked on arduino with the language c
     
  18. ccs_hello

    ccs_hello UDOOer

    Joined:
    Apr 15, 2017
    Messages:
    536
    Likes Received:
    194
    Arduino IDE saves a lot of work on I/O development, especially for folks not seasoned in MCU part of the world.
    So, go for the IDE, it's very easy.

    In Arduino code, include the necessary firmata code such that it can be controlled by the x86 side of the board.
     
  19. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    But the Arduino IDE can only be used in C visibly.
     
  20. pierro

    pierro New Member

    Joined:
    Apr 12, 2019
    Messages:
    25
    Likes Received:
    4
    With the IDE, if I program in language C on my arduino through UDOO (/ ttyACM1), everything is fine

    But if I program on my UDOO (/ ttyACM0), that's it:

    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
     

Share This Page