|
| 1 | + |
| 2 | +Quick start |
| 3 | +=========== |
| 4 | + |
| 5 | +Learn how to work with ino in few minutes. |
| 6 | + |
| 7 | +Creating a project |
| 8 | +------------------ |
| 9 | + |
| 10 | +Let's create a simple project:: |
| 11 | + |
| 12 | + $ mkdir beep |
| 13 | + $ cd beep |
| 14 | + $ ino init -t blink |
| 15 | + |
| 16 | +Here we've created a new directory for our project and initialized project |
| 17 | +skeleton with ``ino init`` command. We chose to use *blink* as a project |
| 18 | +template. That will create a simple sketch for LED blinking on pin 13. |
| 19 | +Lets see what we've got:: |
| 20 | + |
| 21 | + $ tree |
| 22 | + . |
| 23 | + ├── lib |
| 24 | + └── src |
| 25 | + └── sketch.pde |
| 26 | + |
| 27 | + $ cat src/sketch.pde |
| 28 | + |
| 29 | + #define LED_PIN 13 |
| 30 | + |
| 31 | + void setup() |
| 32 | + { |
| 33 | + pinMode(LED_PIN, OUTPUT); |
| 34 | + } |
| 35 | + |
| 36 | + void loop() |
| 37 | + { |
| 38 | + digitalWrite(LED_PIN, HIGH); |
| 39 | + delay(100); |
| 40 | + digitalWrite(LED_PIN, LOW); |
| 41 | + delay(900); |
| 42 | + } |
| 43 | + |
| 44 | +Here we have two directories. ``src`` is a source directory where we can |
| 45 | +put our project's ``*.[c|cpp|pde|h|hpp]`` source files. ``sketch.pde`` |
| 46 | +was created for us, so we have a starting point. ``lib`` is a directory |
| 47 | +where we may put 3-rd party libraries if we would want. |
| 48 | + |
| 49 | +Building |
| 50 | +-------- |
| 51 | + |
| 52 | +Lets build it:: |
| 53 | + |
| 54 | + $ ino build |
| 55 | + Searching for Board description file (boards.txt) ... /usr/local/share/arduino/hardware/arduino/boards.txt |
| 56 | + Searching for Arduino core library ... /usr/local/share/arduino/hardware/arduino/cores/arduino |
| 57 | + Searching for Arduino standard libraries ... /usr/local/share/arduino/libraries |
| 58 | + Searching for Arduino lib version file (version.txt) ... /usr/local/share/arduino/lib/version.txt |
| 59 | + Detecting Arduino software version ... 22 |
| 60 | + Searching for avr-gcc ... /usr/bin/avr-gcc |
| 61 | + Searching for avr-g++ ... /usr/bin/avr-g++ |
| 62 | + Searching for avr-ar ... /usr/bin/avr-ar |
| 63 | + Searching for avr-objcopy ... /usr/bin/avr-objcopy |
| 64 | + Scanning dependencies of src |
| 65 | + src/sketch.cpp |
| 66 | + arduino/wiring_shift.c |
| 67 | + arduino/wiring.c |
| 68 | + arduino/WInterrupts.c |
| 69 | + arduino/wiring_digital.c |
| 70 | + arduino/wiring_pulse.c |
| 71 | + arduino/wiring_analog.c |
| 72 | + arduino/pins_arduino.c |
| 73 | + arduino/HardwareSerial.cpp |
| 74 | + arduino/WString.cpp |
| 75 | + arduino/main.cpp |
| 76 | + arduino/Print.cpp |
| 77 | + arduino/WMath.cpp |
| 78 | + arduino/Tone.cpp |
| 79 | + Linking libcore.a |
| 80 | + Linking firmware.elf |
| 81 | + Converting to firmware.hex |
| 82 | + |
| 83 | +Whew! A lot of work has been done behind the scenes for a single command. |
| 84 | +It's at most about finding necessary tools and directories, and compiling |
| 85 | +the standard core library. Actually you shouldn't care. The consequence |
| 86 | +is that we've got ``firmware.hex``—ready to upload binary file. |
| 87 | + |
| 88 | +Uploading |
| 89 | +--------- |
| 90 | + |
| 91 | +Lets upload it:: |
| 92 | + |
| 93 | + $ ino upload |
| 94 | + Searching for stty ... /bin/stty |
| 95 | + Searching for avrdude ... /usr/local/share/arduino/hardware/tools/avrdude |
| 96 | + Searching for avrdude.conf ... /usr/local/share/arduino/hardware/tools/avrdude.conf |
| 97 | + |
| 98 | + avrdude: AVR device initialized and ready to accept instructions |
| 99 | + |
| 100 | + Reading | ################################################## | 100% 0.00s |
| 101 | + |
| 102 | + avrdude: Device signature = 0x1e950f |
| 103 | + avrdude: reading input file ".build/firmware.hex" |
| 104 | + avrdude: writing flash (428 bytes): |
| 105 | + |
| 106 | + Writing | ################################################## | 100% 0.08s |
| 107 | + |
| 108 | + avrdude: 428 bytes of flash written |
| 109 | + avrdude: verifying flash memory against .build/firmware.hex: |
| 110 | + avrdude: load data flash data from input file .build/firmware.hex: |
| 111 | + avrdude: input file .build/firmware.hex contains 428 bytes |
| 112 | + avrdude: reading on-chip flash data: |
| 113 | + |
| 114 | + Reading | ################################################## | 100% 0.06s |
| 115 | + |
| 116 | + avrdude: verifying ... |
| 117 | + avrdude: 428 bytes of flash verified |
| 118 | + |
| 119 | + avrdude: safemode: Fuses OK |
| 120 | + |
| 121 | + avrdude done. Thank you. |
| 122 | + |
| 123 | +Again, quite much output, but the job is done. Arduino flashes with its |
| 124 | +buil-in LED on pin 13. |
| 125 | + |
| 126 | +Serial communication |
| 127 | +-------------------- |
| 128 | + |
| 129 | +OK, now lets deal with serial communication a bit. With editor of your choice change |
| 130 | +``src/sketch.pde`` to:: |
| 131 | + |
| 132 | + void setup() |
| 133 | + { |
| 134 | + Serial.begin(9600); |
| 135 | + } |
| 136 | + |
| 137 | + void loop() |
| 138 | + { |
| 139 | + Serial.println(millis()); |
| 140 | + delay(1000); |
| 141 | + } |
| 142 | + |
| 143 | +This should transmit number of milliseconds spent from power up every second via |
| 144 | +serial port. Lets build it:: |
| 145 | + |
| 146 | + $ ino build |
| 147 | + Scanning dependencies of src |
| 148 | + src/sketch.cpp |
| 149 | + Linking firmware.elf |
| 150 | + Converting to firmware.hex |
| 151 | + |
| 152 | +As you can see much fewer of steps have been performed behind the scenes. It is |
| 153 | +because only things that have been changed are taken into account. This boosts |
| 154 | +up the build. |
| 155 | + |
| 156 | +Lets upload it with ``ino upload``. When uploading is done lets connect to the |
| 157 | +device with serial monitor to see what it prints:: |
| 158 | + |
| 159 | + $ ino serial |
| 160 | + Searching for Serial monitor (picocom) ... /usr/bin/picocom |
| 161 | + picocom v1.4 |
| 162 | + |
| 163 | + port is : /dev/ttyACM0 |
| 164 | + flowcontrol : none |
| 165 | + baudrate is : 9600 |
| 166 | + parity is : none |
| 167 | + databits are : 8 |
| 168 | + escape is : C-a |
| 169 | + noinit is : no |
| 170 | + noreset is : no |
| 171 | + nolock is : yes |
| 172 | + send_cmd is : ascii_xfr -s -v -l10 |
| 173 | + receive_cmd is : rz -vv |
| 174 | + |
| 175 | + Terminal ready |
| 176 | + 0 |
| 177 | + 1000 |
| 178 | + 2004 |
| 179 | + 3009 |
| 180 | + 4014 |
| 181 | + |
| 182 | +That's what we want! Press Ctrl+A Ctrl+X to exit. |
| 183 | + |
| 184 | +Tweaking parameters |
| 185 | +------------------- |
| 186 | + |
| 187 | +All examples were done in assumption that you have Arduino Uno and it is |
| 188 | +available on default port. Now consider you have Arduino Mega 2560 and |
| 189 | +it is available on port ``/dev/ttyACM1``. We have to specify this for |
| 190 | +our build steps as command-line switches. |
| 191 | + |
| 192 | +Board model may be set with ``--board-model`` or ``-m`` switch. Port |
| 193 | +is set with ``--serial-port`` or ``-p`` switch. So lets do it:: |
| 194 | + |
| 195 | + $ ino build -m mega2560 |
| 196 | + $ ino upload -m mega2560 -p /dev/ttyACM1 |
| 197 | + $ ino serial -p /dev/ttyACM1 |
| 198 | + |
| 199 | +It can be annoying to provide these switches over and over again. So |
| 200 | +you can save them in ``ino.ini`` file in project directory. Put |
| 201 | +following lines to the ``ino.ini``:: |
| 202 | + |
| 203 | + [build] |
| 204 | + board-model = mega2560 |
| 205 | + |
| 206 | + [upload] |
| 207 | + board-model = mega2560 |
| 208 | + serial-port = /dev/ttyACM1 |
| 209 | + |
| 210 | + [serial] |
| 211 | + serial-port = /dev/ttyACM1 |
| 212 | + |
| 213 | +Now you can build, upload and communicate via serial not having to provide |
| 214 | +any parameters. Well, in most cases if you build for Mega 2560, you will |
| 215 | +want to upload to Mega 2560 as well. The same about serial port setting. |
| 216 | +So to don't repeat settings for different commands shared switches could |
| 217 | +be moved up to an unnamed section. So having just following lines in ``ino.ini`` |
| 218 | +is enough:: |
| 219 | + |
| 220 | + board-model = mega2560 |
| 221 | + serial-port = /dev/ttyACM1 |
| 222 | + |
| 223 | +Furthermore, if you have Mega 2560, it is likely that you have it for all |
| 224 | +projects you make. You can put a shared configuration file to either:: |
| 225 | + |
| 226 | + 1. /etc/ino.ini |
| 227 | + 2. ~/inorc |
| 228 | + |
| 229 | +And it'll be used for setting default parameter values if they're not |
| 230 | +overriden by the local ``ino.ini`` or by explicit command-line switches. |
0 commit comments