Download presentation
Presentation is loading. Please wait.
1
Seminars at RSSC.org Sergei Grichine slg@quakemap.com
2
Agenda Why Arduino Common boards – Uno, Mega, Pro Mini, Leonardo and just a chip
3
Why Arduino Well designed cheap hardware Insanely simple programming at the beginning Friendly IDE – “keep it simple-stupid!” Exceptional documentation Community support, samples, forums, experts Have a question? Just google it!
4
Common boards: Uno
5
Common boards: Mega 2560
6
Leonardo – full USB
7
A no-board solution – just an ATmega328 chip
8
Pro Mini 328 5V
9
Tools –
10
Arduino Specs Not much power – 16 MHz crystal, close to 16 MIPS 8-bit AVR instruction set Uno / ATmega328 Flash Memory: 32 KB of which 0.5 KB used by bootloader SRAM: 2 KB (a.k.a. RAM) EEPROM: 1 KB(persistent storage for settings) Mega: Flash Memory: 256 KB of which 8 KB used by bootloader SRAM: 8 KB EEPROM: 4 KB
11
Code tips Not C++, Not quite Java – but close Google “arduino reference” Functions - http://arduino.cc/en/Reference/HomePage http://arduino-info.wikispaces.com/HOME
12
Code tour Code: Serial communication to a PC Cooperative Multitasking Preemptive Multitasking
13
Serial Communication BalancerHeadServo Short ASCII messages (one-liners) Start symbol (for example, *) Channel Command Position-based, separated values Checksum *3 5 456 553 87 214
14
Serial Communication (PC side)
15
Serial Communication (Arduino side) BalancerHeadServo
16
Serial Communication (Timing) At 115200 baud = 10K bytes/sec *3 5 456 553 87 214 20 characters = 2ms At 9600 baud – 25ms
17
Multitasking Typical tasks: Read Sensors Compute Actuate Communicate
18
Cooperative Multitasking Call functions from the loop() Expect functions to return promptly Common “tick” maintained by the loop code Individual timing logic for each function
19
Cooperative Multitasking BalancerDfr
20
Cooperative Multitasking Everything is tied together Delays can cause failure Poor separation of code
21
Preemptive Multitasking Some kind of OS/Dispatcher required Tasks are independent functions Tasks are interrupted at any time Tasks can sleep() and yield() Use “volatile” for shared variables
22
Preemptive Multitasking BalancerHeadServo #include AVR_OS os = AVR_OS(); // Create instance of OS multitasker os.os_init(); os.os_schedule_task(taskReadFeedbackPot, NULL, 0); os.os_schedule_task(taskActuate, NULL, 0); os.os_schedule_task(taskRemote, NULL, 0); os.os_schedule_task(taskReportState, NULL, 0); loop() { os.os_loop(); }
23
Preemptive Multitasking // Define task 3 - check for commands over the serial line void taskRemote(void *arg) { while(1) { if(!CheckSerial()) // false if no input { os.os_sleep(20); // no input; must be at least TICK_INTERVAL 2 } else { os.os_yield(); // have more to read }
24
Seminars at RSSC.org Sergei Grichine slg@quakemap.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.