Search code examples
pythonarduinoaccelerometergyroscope

Can I use Python (with pyfirmata) to read and use data from a gyroscope connected to an Arduino?


I have my Arduino hooked up via serial to my computer and can do basic digital writes and stuff to the Arduino with Python (using the pyfirmata library). So what I'd like to know is whether or not I can make use of gyroscopes and accelerometers with pyfirmata?


Solution

  • Yes you Can.

    I don't know much about pyfirmata, however it looks like it is based on pyserial. Which I have used a bit in the passed. I will tell you what I know about pyserial

    on the arduino

    void setup() {
     // open the serial port at 9600 bps:
     Serial.begin(9600);
     }
    

    on the PC python terminal

    >>> ser = serial.Serial()
    >>> ser.baudrate = 9600         <--same as the arduino void setup()
    >>> ser.port = 0                <--Name of the virtual com port
    >>> ser.open
    

    When you write from one you can read from the other.

    http://arduino.cc/en/Reference/Serial http://pyserial.sourceforge.net/shortintro.html