Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
public:openlab:autumn2014:arduino [2015-02-10 21:18]
lnemec images moved to openlab namespace
public:openlab:autumn2014:arduino [2016-12-01 14:28] (current)
Line 1: Line 1:
 ====== OpenLab 2014/07 | Hands on Arduino ====== ====== OpenLab 2014/07 | Hands on Arduino ======
  
-  * Date: 31. 10. 2014+  * Date: 31. 10. 2014 && 11.3.2016
   * Workshop by: Lukáš Němec   * Workshop by: Lukáš Němec
   * Cake: we will see...   * Cake: we will see...
-  * Cake by: Mirek Jaroš 
-  * Discussion on A403 wallpainting 
  
 ===== What to expect ===== ===== What to expect =====
  
-Introduction to microcontroller programmingfocused mainly on Arduino platform. We will start with basics, what to expect from Arduino and what is Arduino capable of with some examples. Then theoretic part, how to connect everything together and mainly how to write programs. Thus everything from using basic C skills to Arduino specific functions. +Introduction to microcontroller programming focused mainly on Arduino platform. We will start with basics, what to expect from Arduino and what is Arduino capable of with some examples. Then theoretic part, how to connect everything together and mainly how to write programs. Thus everything from using basic C skills to Arduino-specific functions. 
  
-As we learn enough of theoretic background, you will get your hands on Arduino boards and you will have chance to program your own blinking LED or something similar, depending on your time, skill and enthusiasm.+As we learn enough of theoretic background, you will get your hands on Arduino boards and you will have chance to program your own blinking LED or something similar, depending on your time, skill and enthusiasm.
  
 ===== What to prepare ===== ===== What to prepare =====
Line 21: Line 19:
     - Google and own imagination ;-)     - Google and own imagination ;-)
                  
-There will be supply of leds, resistors, some sensors (light, temperature, IR ...) and bunch of other arduino related stuff.+There will be supply of LEDs, resistors, some sensors (light, temperature, IR ...) and bunch of other Arduino related stuff.
  
 ===== Arduino Theory ===== ===== Arduino Theory =====
Line 29: Line 27:
 ==== Arduino Ecosystem ==== ==== Arduino Ecosystem ====
  
-Arduino is phenomenon of last few years, quickly gaining popularity in many fileds. It originated somewhere in DIY community as easily managable microcontroller with Open-Source design, that was accesible to everyone. With this huge succes, family of official Arduino board quickly grew, as well as all other products, that were somehow Arduino related. +Arduino is phenomenon of last few years, quickly gaining popularity in many fields. It originated somewhere in DIY community as easily manageable microcontroller with Open-Source design, that was accessible to everyone. With this huge successfamily of official Arduino board quickly grew, as well as all other products, that were somehow Arduino related. 
  
-Today There is huge selection of boards, starting from basic UNO, litle bit more advanced Leonardo, up to Arduino MEGA. On the other side, if you are interested in smaller sizes, there is Arduino micro, mini and nano, some that small, that there is no space for usb connectivity. Also, if you want to keep up with latest developement, you can try out Arduino Yún or soon comming Arduino Tre. There is also market for special purpose microcontrolers, like wearable electronics, which can be designed using Arduino LillyPad and conductive thread. +Today There is huge selection of boards, starting from basic UNO, a little bit more advanced Leonardo, up to Arduino MEGA. On the other side, if you are interested in smaller sizes, there is Arduino micro, mini and nano, some that small, that there is no space for USB connectivity. Also, if you want to keep up with the latest development, you can try out Arduino Yún or soon to come Arduino Tre. There is also market for special purpose microcontrollers, like wearable electronics, which can be designed using Arduino LillyPad and conductive thread. 
  
-Also open source design of Arduino is by many viewed as perfect point to start with own modifications, for example Jeenodes - Arduino based WSN modules. Also there is wide range of unofficial boards, that just take open source design, and sell it under different name with cheaper price (Funduino, Robotino etc. usually called Arduino compatible HW)+Also open source design of Arduino is by many viewed as the perfect point to start with own modifications, for exampleJeenodes - Arduino based WSN modules. Alsothere is wide range of unofficial boards, that just take open source design, and sell it under different name with cheaper price (Funduino, Robotino etc. usually called Arduino compatible HW)
  
-Concerning accesoris, there are many shields, which can add specific functionality to your arduino, for example GSM of WIFI shields. These become usefull, when you are building a diet control machine, that will publish tweet every time you open door to your fridge. Also there is wide range of sensors, so you can measure almost everything, from light and humidity to methane concentration.+Concerning accessories, there are many shields, which can add specific functionality to your Arduino, for exampleGSM of WIFI shields. These become useful when you are building a diet control machine, that will publish tweet every time you open door to your fridge. Alsothere is wide range of sensors, so you can measure almost everything, from light and humidity to methane concentration.
  
 ==== How to connect everything together ==== ==== How to connect everything together ====
  
-Every arduino has pins, usually with sothered sockets, but you can also buy just bare PCBs and make sothering yourselfif you ever need to do so. There are three basic categories of pins: analog, digital and power + some special purpose ones. Pins are usually numbered or labeled, and you can see these directly on the board.+Every Arduino has pins, usually with other sockets, but you can also buy just bare PCBs and make sothering yourself if you ever need to do so. There are three basic categories of pins: analog, digital and power + some special purpose ones. Pins are usually numbered or labeled, and you can see these directly on the board.
  
 ===Digital pins=== ===Digital pins===
-Use digital signal, thus input and output has only two possible values. These are 1 and 0, or in practical view, 5V or nothing. Digital pins can be also used to read data, but again only two states, so ideal choice for switches. To make things little bit more tricky, some digital pins have pulse-width modulation (PWM) enabeled and these are usually labelled with ∼. These pins can be used for analog write commands, in other way, output can be set anywhere between 0 and 255. These can be used for a dimmer or precise positioning of servo motors.+Use digital signal, thus input and output has only two possible values. These are 1 and 0, or in practical view, 5V or nothing. Digital pins can be also used to read data, but again only two states, so ideal choice for switches. To make things little bit more tricky, some digital pins have pulse-width modulation (PWM) enabled and these are usually labelled with ∼. These pins can be used for analog write commands, in other way, output can be set anywhere between 0 and 255. These can be used for a dimmer or precise positioning of servo motors.
  
 ===Analog pins=== ===Analog pins===
-Analog pins are used for analog readwhen we need more precise value than just binary 0 or 1. Output from these pins can be anything between 0 to 1023 and we use these pins for reading values from sensors, e.g. humidity, ligth, distance etc.+Analog pins are used for analog read when we need more precise value than just binary 0 or 1. The output from these pins can be anything between 0 to 1023 and we use these pins for reading values from sensors, e.g. humidity, light, distance etc.
  
 === Power and special pins === === Power and special pins ===
  
-Last category of pins are power pins, these are ground pins, 5V and 3.5V pins. Connect these to power breadboard power lines or components directly, as needed.+The last category of pins are power pins, these are ground pins, 5Vand 3.5V pins. Connect these to power breadboard power lines or components directly, as needed.
  
-All other pins are used for special purposes, like reset pin or in case of smaller or older versions of arduino for actual programming (USB interface is not present).+All other pins are used for special purposes, like reset pin or in case of smaller or older versions of Arduino for actual programming (USB interface is not present).
  
 <note important>Reset pin is usually present also in form of a button on board, this can be used for reinitializing state of your code back to setup function.</note> <note important>Reset pin is usually present also in form of a button on board, this can be used for reinitializing state of your code back to setup function.</note>
  
 ==== How to upload code ==== ==== How to upload code ====
-Recomended steps:+Recommended steps:
  
-  - Connect arduino to PC, usually USB cable type B, or micro USB with new boards.+  - Connect Arduino to PC, usually USB cable type B, or micro USB with new boards.
   - Start Arduino IDE   - Start Arduino IDE
   - Select Tools - Board Type (mostly Arduino UNO)   - Select Tools - Board Type (mostly Arduino UNO)
-  - Select Tools - Serial Port (there will be usually only onewhen only one arduino board is connected)+  - Select Tools - Serial Port (there will be usually only one when only one Arduino board is connected)
   - Write your code or open some example sketches (or load some saved sketches)   - Write your code or open some example sketches (or load some saved sketches)
-  - Do all the wiring (can be done as first step or as last)+  - Do all the wiring (can be done as the first step or as last)
   - Press Ctrl + R to compile   - Press Ctrl + R to compile
-  - Press Ctrl + U to upload code to your arduino+  - Press Ctrl + U to upload code to your Arduino
   - Optionally repeat while fixing bugs or adding features (two names for the same thing)   - Optionally repeat while fixing bugs or adding features (two names for the same thing)
  
Line 86: Line 84:
 === Blinking LED === === Blinking LED ===
  
-Now for some code, that actually does something usefull (blinking LED):+Now for some code, that actually does something useful (blinking LED):
 <code C> <code C>
 //global constant for more comprehensible code, you can use just number,  //global constant for more comprehensible code, you can use just number, 
-//this way it is just more user friendly when handling multiple pins+//this way it is just more user-friendly when handling multiple pins
 int ledPin = 13;  int ledPin = 13; 
  
Line 107: Line 105:
 </code> </code>
  
-This code also requires some basic assembly, LED needs to be connected to arduino, it is recomended to use breadboard and some jumper wires, exact way is illustrated on image below. +This code also requires some basic assembly, LED needs to be connected to Arduino, it is recommended to use breadboard and some jumper wires, an exact way is illustrated on the image below. 
  
 <note important>When connecting LED, remember that LEDs are like all other diodes, so electricity flows in one direction only. The longer lead is positive (anode) needs to be connected to power and shorter leg (cathode) to ground.</note>  <note important>When connecting LED, remember that LEDs are like all other diodes, so electricity flows in one direction only. The longer lead is positive (anode) needs to be connected to power and shorter leg (cathode) to ground.</note> 
-<note warning>LEDs are not capable of handling arduino's 5V power, so resistor is required. Usually one which has 220Ω is used, but in this case it is not necessary to be exact, so you can use 200Ω or 300Ω as well and it will slightly affect brightness of LED, but nothing more. Generally more resistance does no harm, less resistance could burn the LED.</note>+<note warning>LEDs are not capable of handling Arduino's 5V power, so resistor is required. Usually one which has 220Ω is used, but in this case it is not necessary to be exact, so you can use 200Ω or 300Ω as well and it will slightly affect brightness of LED, but nothing more. Generally more resistance does no harm, less resistance could burn the LED.</note>
  
 {{ :public:openlab:led_blink.png?direct&700 |}} {{ :public:openlab:led_blink.png?direct&700 |}}
Line 117: Line 115:
 Next example will show, how to read values from sensors and how to obtain debugging information from Arduino board. Next example will show, how to read values from sensors and how to obtain debugging information from Arduino board.
  
-In order to receive value from sensor, we have to use analog input pins (Arduino UNO has range from A0 to A5) and read values with analogRead function. There are many posibilities what to use as a source of input, you can choose from whatever is avaiable, rotary potentiometer, light resistor (changes resistivity based on light) or any other option you choose. +In order to receive value from sensor, we have to use analog input pins (Arduino UNO has range from A0 to A5) and read values with analogRead function. There are many possibilities what to use as a source of input, you can choose from whatever is available, rotary potentiometer, light resistor (changes resistivity based on light) or any other option you choose. 
  
-Every sensor (save he more complicated ones) has basically three connections, power (Arduino's 5V), ground and output. Output is connected to analog input pin, in case of image below, two options are illustrated, one light resistor (with another 10KΩ resistor for better results) and one rotary potentiometer, both produce analog values from 0 to 1023while read with analogRead function. +Every sensor (save the more complicated ones) has basically three connections, power (Arduino's 5V), ground and output. The output is connected to the analog input pin, in the case of an image below, two options are illustrated, one light resistor (with another 10KΩ resistor for better results) and one rotary potentiometer, both produce analog values from 0 to 1023 while reading with analogRead function. 
  
-Next is serial output, which can be used either for debugging or logging values. Output needs to be inicialized in setup phase with following ''Serial.begin(9600);'' where 9600 means frequency in bauds. Then you can use ''Serial.println("text");'' anywhere in code. This messages can be captured, if you open Serial monitor from IDE (shortcut CTRL+Shift+M) and select same frequency as previously. +Next is serial output, which can be used either for debugging or logging values. Output needs to be initialized in setup phase with following ''Serial.begin(9600);'' where 9600 means frequency in bauds. Then you can use ''Serial.println("text");'' anywhere in code. This messages can be captured, if you open Serial monitor from IDE (shortcut CTRL+Shift+M) and select same frequency as previously. 
  
 <code C> <code C>
Line 149: Line 147:
  
 ==== Ideas, where to get them ==== ==== Ideas, where to get them ====
-As stated previously, idea is begining of everything, thus you need ideas what to do with Arduino. Hopefully you can come up with many of your own, but if you need some inspiration boost, following might help:+As stated previously, the idea is begining of everything, thusyou need ideas what to do with Arduino. Hopefullyyou can come up with many of your own, but if you need some inspiration boost, following might help:
   * Arduino Started Kit (book of 15 tutorials together with Arduino board and parts you will need)   * Arduino Started Kit (book of 15 tutorials together with Arduino board and parts you will need)
   * Other official Arduino Examples and already finished projects http://arduino.cc/   * Other official Arduino Examples and already finished projects http://arduino.cc/
Line 156: Line 154:
  
 ==== What to buy ==== ==== What to buy ====
-You will need something to start with, either you already have some electronics, and you just need ome jump start into it, or you are starting from scratch. Either way, there are many ways to spend your budget, so here comes list of essential parts and tools and also list of nice things to have, but which you can do without.  +You will need something to start with, either you already have some electronics, and you just need ome jump start into it, or you are starting from scratch. Either way, there are many ways to spend your budget, so here comes list of essential parts and tools and also list of nice things to have, but which you can do without.  
  
 === Essential === === Essential ===
Line 181: Line 179:
 ===== JeeNodes ===== ===== JeeNodes =====
  
-Jeenodes are special purpose boards (Arduino based) for WSN networks. Because of these facts, there is limited number of pinsand some other limitations, but for our cause they will be more than sufficient and only few changes has to be made. +Jeenodes are special purpose boards (Arduino based) for WSN networks. Because of these facts, there is limited number of pins and some other limitations, but for our cause they will be more than sufficient and only few changes have to be made. 
  
-First connections, following image shows how to connect JeeNode, LED and resistor together, especially which ports to use, since they are not as nicely labelled as other Arduino boards. +First connections, following imageshows how to connect JeeNode, LED and resistor together, especially which ports to use, since they are not as nicely labeled as other Arduino boards. 
  
 {{ :public:openlab:jeenode_led.png?direct&500|}} {{ :public:openlab:jeenode_led.png?direct&500|}}