gobot.io/x/gobot/v2@v2.1.0/platforms/firmata/README.md (about) 1 # Firmata 2 3 Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists and anyone interested in creating interactive objects or environments. 4 5 This package provides the adaptor for microcontrollers such as Arduino that support the [Firmata](https://github.com/firmata/protocol) protocol 6 7 You can connect to the microcontroller using either a serial connection, or a TCP connection to a WiFi-connected microcontroller such as the ESP8266. 8 9 For more info about the Arduino platform, go to [http://arduino.cc/](http://arduino.cc/). 10 11 ## How to Install 12 13 ``` 14 go get -d -u gobot.io/x/gobot/v2/... 15 ``` 16 17 You must install Firmata on your microcontroller before you can connect to it using Gobot. You can do this in many cases using Gort ([http://gort.io](http://gort.io)). 18 19 In order to use a TCP connection with a WiFi-enbaled microcontroller, you must install WifiFirmata on the microcontroller. You can use the Arduino IDE to do this. 20 21 ## How to Use 22 23 With a serial connection: 24 25 ```go 26 package main 27 28 import ( 29 "time" 30 31 "gobot.io/x/gobot/v2" 32 "gobot.io/x/gobot/v2/drivers/gpio" 33 "gobot.io/x/gobot/v2/platforms/firmata" 34 ) 35 36 func main() { 37 firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") 38 led := gpio.NewLedDriver(firmataAdaptor, "13") 39 40 work := func() { 41 gobot.Every(1*time.Second, func() { 42 led.Toggle() 43 }) 44 } 45 46 robot := gobot.NewRobot("bot", 47 []gobot.Connection{firmataAdaptor}, 48 []gobot.Device{led}, 49 work, 50 ) 51 52 robot.Start() 53 } 54 ``` 55 56 With a TCP connection, use the `NewTCPAdaptor`: 57 58 ```go 59 package main 60 61 import ( 62 "time" 63 64 "gobot.io/x/gobot/v2" 65 "gobot.io/x/gobot/v2/drivers/gpio" 66 "gobot.io/x/gobot/v2/platforms/firmata" 67 ) 68 69 func main() { 70 firmataAdaptor := firmata.NewTCPAdaptor("192.168.0.66:3030") 71 led := gpio.NewLedDriver(firmataAdaptor, "2") 72 73 work := func() { 74 gobot.Every(1*time.Second, func() { 75 led.Toggle() 76 }) 77 } 78 79 robot := gobot.NewRobot("bot", 80 []gobot.Connection{firmataAdaptor}, 81 []gobot.Device{led}, 82 work, 83 ) 84 85 robot.Start() 86 } 87 ``` 88 89 **Important** note that analog pins A4 and A5 are normally used by the Firmata I2C interface, so you will not be able to use them as analog inputs without changing the Firmata sketch. 90 91 92 ## How to Connect 93 94 ### Upload the Firmata Firmware to the Arduino 95 96 This section assumes you're using an Arduino Uno or another compatible board. If you already have the Firmata sketch installed, you can skip straight to the examples. 97 98 ### OS X 99 100 First plug the Arduino into your computer via the USB/serial port. 101 A dialog box will appear telling you that a new network interface has been detected. 102 Click "Network Preferences...", and when it opens, simply click "Apply". 103 104 Once plugged in, use [Gort](http://gort.io)'s `gort scan serial` command to find out your connection info and serial port address: 105 106 ``` 107 $ gort scan serial 108 ``` 109 110 Use the `gort arduino install` command to install `avrdude`, this will allow you to upload firmata to the arduino: 111 112 ``` 113 $ gort arduino install 114 ``` 115 116 Once the avrdude uploader is installed we upload the firmata protocol to the arduino, use the arduino serial port address found when you ran `gort scan serial`: 117 118 ``` 119 $ gort arduino upload firmata /dev/tty.usbmodem1421 120 ``` 121 122 Now you are ready to connect and communicate with the Arduino using serial port connection 123 124 Note that Gobot works best with the `tty.` version of the serial port as shown above, not the `cu.` version. 125 126 ### Ubuntu 127 128 First plug the Arduino into your computer via the USB/serial port. 129 130 Once plugged in, use [Gort](http://gort.io)'s `gort scan serial` command to find out your connection info and serial port address: 131 132 ``` 133 $ gort scan serial 134 ``` 135 136 Use the `gort arduino install` command to install `avrdude`, this will allow you to upload firmata to the arduino: 137 138 ``` 139 $ gort arduino install 140 ``` 141 142 Once the avrdude uploader is installed we upload the firmata protocol to the arduino, use the arduino serial port address found when you ran `gort scan serial`, or leave it blank to use the default address `ttyACM0`: 143 144 ``` 145 $ gort arduino upload firmata /dev/ttyACM0 146 ``` 147 148 Now you are ready to connect and communicate with the Arduino using serial port connection 149 150 ### Windows 151 152 First download and install gort for your OS from the [gort.io](gort.io) [downloads page](http://gort.io/documentation/getting_started/downloads/) and install it. 153 154 Open a command prompt window by right clicking on the start button and choose `Command Prompt (Admin)` (on windows 8.1). Then navigate to the folder where you uncompressed gort (uncomress to a folder first if you haven't done this yet). 155 156 Once inside the gort folder, first install avrdude which we'll use to upload firmata to the arduino. 157 158 ``` 159 $ gort arduino install 160 ``` 161 162 When the installation is complete, close the command prompt window and open a new one. We need to do this for the env variables to reload. 163 164 ``` 165 $ gort scan serial 166 ``` 167 168 Take note of your arduinos serialport address (COM1 | COM2 | COM3| etc). You need to already have installed the arduino drivers from [arduino.cc/en/Main/Software](https://www.arduino.cc/en/Main/Software). Finally upload the firmata protocol sketch to the arduino. 169 170 ``` 171 $ gort arduino upload firmata <COMX> 172 ``` 173 174 Make sure to substitute `<COMX>` with the apropiate serialport address. 175 176 Now you are ready to connect and communicate with the Arduino using serial port connection. 177 178 ### Using arduino IDE 179 180 Open arduino IDE and go to File > Examples > Firmata > StandardFirmata and open it. Select the appriate port 181 for your arduino and click upload. Wait for the upload to finish and you should be ready to start using Gobot 182 with your arduino. 183 184 ## Hardware Support 185 The following Firmata devices have been tested and are known to work: 186 187 - [Arduino Uno R3](http://arduino.cc/en/Main/arduinoBoardUno) 188 - [Arduino/Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101) 189 - [Teensy 3.0](http://www.pjrc.com/store/teensy3.html) 190 191 The following WiFi devices have been tested and are known to work: 192 - [NodeMCU 1.0](http://nodemcu.com/index_en.html) 193 194 More devices are coming soon...