1 | \title{FACT Arduino ethernet communication Interface }
|
---|
2 |
|
---|
3 | \section{Introduction}
|
---|
4 | Arduino is the name of a series of open source
|
---|
5 | microcontroller equipped boards. The
|
---|
6 | microcontroller in use is out of Atmels ATmega family.
|
---|
7 |
|
---|
8 | The FACT telescope uses mostly the Arduino Ethernet board to
|
---|
9 | monitor and control certain auxiliary systems like the motors of the camera
|
---|
10 | shutter.
|
---|
11 |
|
---|
12 | This board was chosen since the needed hardware for ethernet access,
|
---|
13 | like a dedicated ethernet controller (Wiznet W5100) and the jack, are already
|
---|
14 | in place. In addition the programming of the board, in comparably easy.
|
---|
15 |
|
---|
16 | Setting up a TCP/IP server (using a fix IP or a DHCP server) as well as
|
---|
17 | raw byte-stream communication with clients is handled by the Ethernet library,
|
---|
18 | which comes with the Arduino IDE.
|
---|
19 |
|
---|
20 | There is a variety of open source extension boards available for the Arduino,
|
---|
21 | both from the Arduino group as well as from unrelated developers. These
|
---|
22 | extension boards are usually called shields.
|
---|
23 | The shields can be connected to the ATmega port pins via 100mil headers,
|
---|
24 | which can be used to connect custom peripherals as well.
|
---|
25 |
|
---|
26 | Typical ATmega digital outputs can drive up to 10mA at 5.0V and thus allow for
|
---|
27 | quick connection of LEDs for software tests or similar quick hacks.
|
---|
28 |
|
---|
29 | There exists an open source C cross compiler for Atmega as well a std-lib
|
---|
30 | implementation. The Arduino group created not only a user friendly
|
---|
31 | (maybe not power user friendly) IDE but also supplies the beginner with a
|
---|
32 | bunch of useful classes from serial communication to LCD interfacing.
|
---|
33 |
|
---|
34 | \subsection{std C vs. Arduino quasi C++}
|
---|
35 | The Arduino IDE provides the beginner with a simple programming enviroment.
|
---|
36 | While the usual microcontroller program comprises of an init section
|
---|
37 | and a never ending while loop which contains the actual job of the microcontroller,
|
---|
38 | e.g. like this:
|
---|
39 | \begin{verbatim}
|
---|
40 | void main (void){
|
---|
41 |
|
---|
42 | // set up peripherals and I/O pins
|
---|
43 | // e.g:
|
---|
44 | DDRD |= 1<<PD6; // define pin PD6 to be an output
|
---|
45 |
|
---|
46 | // herein the actual 'job' is performed
|
---|
47 | while(1){
|
---|
48 | // toggle the output
|
---|
49 | PORTD ^= 1<<PD6;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | This would look like this in Arduino quasi C++:
|
---|
54 | \begin{verbatim}
|
---|
55 | // On the Arduino board there are numbers printed
|
---|
56 | // next to the 100mil header sockets.
|
---|
57 | // The ATmega pin PD6 is named '6' on the Arduino board.
|
---|
58 | const int my_output_pin = 6;
|
---|
59 |
|
---|
60 | setup(){
|
---|
61 | pinMode( my_output_pin, OUTPUT);
|
---|
62 | boolean output_pin_state = false;
|
---|
63 | }
|
---|
64 | loop(){
|
---|
65 | // toggle the variable...
|
---|
66 | output_pin_state = !output_pin_state;
|
---|
67 | // write the value of the value, to the pin
|
---|
68 | digitalWrite( my_output_pin, output_pin_state);
|
---|
69 | }
|
---|
70 | \end{verbatim}
|
---|
71 |
|
---|
72 | In many cases, the code written in the Arduino-C++ dialect does not
|
---|
73 | produce the optimal binary, but one can always fall back to standard C
|
---|
74 | and even use both styles of writing in one and the same source file.
|
---|
75 |
|
---|
76 | \subsection{ scheduling on microcontrollers }
|
---|
77 | There is nothing like a schedular running on a microcontroller, so one can not
|
---|
78 | produce concurrent running code by using threads. The developer needs
|
---|
79 | in such a case to implement a form of time sharing himself.
|
---|
80 |
|
---|
81 | Assume the following task:
|
---|
82 | The ATmegas internal ADC should be used to measure a voltage as soon
|
---|
83 | as an attached button is pressed. Since we expect some noise, the ADC should
|
---|
84 | sample the voltage 100 times and return the mean and the std deviation.
|
---|
85 | Since the user is expected to be slow, when pressing a button, 50 of the samples
|
---|
86 | shoule be taken, before the user pressed the button.
|
---|
87 | We assume the CPU frequency is 16MHz. And the serial communication to run at
|
---|
88 | 9600 baud.
|
---|
89 |
|
---|
90 | The ADC needs about 130us for a conversion.
|
---|
91 |
|
---|
92 |
|
---|
93 | (Although there might be libraries easing the pain a little out there.)
|
---|
94 | The most prominent solution maybe looks like this
|
---|
95 | \begin{verbatim}
|
---|
96 | loop(){
|
---|
97 | check_if_a_button_was_pressed();
|
---|
98 | check_if_the_ADC_has_a_valid_reading();
|
---|
99 | calculate_something();
|
---|
100 | tell_the_world_about_it(); //9600 baud serial communication
|
---|
101 | }
|
---|
102 | In case each of the functions runs only a for little amount of time,
|
---|
103 | say about 10ms. the user experience is, that the reaction on a pressed button
|
---|
104 | is immediate. Assume the ADC needs multiples of about 50ms to get a valid reading,
|
---|
105 | it is assured, that the ADC value is read out of the ADC reagister as soon as
|
---|
106 | it is valid, and the
|
---|
107 |
|
---|
108 | \end{verbatim}
|
---|
109 |
|
---|
110 |
|
---|
111 | \section{Usage}
|
---|
112 |
|
---|
113 | \section{Implementation}
|
---|
114 |
|
---|
115 | \section{Summary} |
---|