To get a better idea of how a simple network works, I started with trying out neil's
hello.bus.45 example.
My tutor already had the example boards ready, but the 6 pin headers were still missing,
so I soldered that.
Then I tried out the code to see how it works.
I used putty (tried in week 8) to get them to blink for me.
C:\dev\hello-bus>make -f hello.bus.45.make
#define node_id '1'
What is important, is that every board gets a different id, so when you ask (trough putty),
the right board blinks back.
So every node listens and all blink once, and the node addressed blinks a second time.
25 april 2014 | connecting my boards
For my final project I need my touch sensor board (made in
week 10) to talk to my servo board (made in
week 12).
Without changing the design of the boards, I can use:
servo
>
touch
miso PA5 serial_pin_out
>
mosi PB0 serial_pin_in
sck PA4 serial_pin_in
>
sck PB2 serial_pin_out
vcc
>
vcc
gnd
>
gnd
rst
>
rst
mosi
>
miso
28 april 2014 | re-programming my touch sensor board
With lots of explanation form my tutor about how my new code should work and why etc,
I've written out a description of my code:
touch board - description:
function 1:
continuous measuring
calculating average of measurement
function 2:
respond to request from master
if request is directed to him, answer with giving the calculated average measurement
Note: We choose to communicate via a wires protocol.
Because of the limited available pins, we choose to communicate via serial connection.
(SPI > not enough available pins), (serial > RS232 is easier to debug than I2C).
How the 2 boards communicate:
Master (servo board) will send a ID of 1 byte
the addressed slave (touch board) will respond by sending back 6 averages of 2 bytes each.
function 1 - details:
continuously measure 3 intervals from sensor 1
continuously measure 3 intervals from sensor 2
after each measurement:
check if a byte has been recieved
- if yes, send all the calculated average
- else no, continue...
clear the received byte
function 2 - details:
communications starts - main loop:
check if a byte has been received
(1 byte received: interrupt: respond within reasonable short time
- if yes, is byte same is own ID?
- if yes, respond with calculated results
29 april 2014 | new code for touch sensor
#define node_id '1' //touch sensor board is named '1'
void send_result () { // function to calculate and send result
1 may 2014 | re-programming my servo board
servo board - description:
function 1:
have 2 servo's move independend
(sending periodically position to servo)
function 2:
periodically request sensor value's
calcultaing new servo postion, bases on recieved sensor value's
function 3:
fluent transition of old to new servo position
function 1 - details:
generate PWM, based in timer
function 2 - details:
requesting value's:
- defining via serieel
- initialising via serieel
track time: have (+/-) 20ms passed?
- if yes, send out ID, recieve the awser and rebuild the (new) value's
value: is this number is less then the 'normal' value?
- if yes, move servo in popsite direcion
- if no, nothing happens
movement: is movement still possible without reaching the limit of the servo?
- if yes, proceed with servo movement
- else no, move servo in oppisite direction (note: this step still needs a better defined disciption to prevent conflict)
function 3 - details:
optional (if time permits ...)
2 may 2014 | new code for servo board
#define servoMIN 1250
#define servoMAX 6400
#define servoMID ((servoMAX - servoMIN) / 2 + servoMIN) // calculating steps to center position of servo
#define servoSMALLSTEP 100
if (adc0_avg1 <= 400) { // when yellow sensor (intv 1) is touched directly, servo's move the tail to the left
if (OCR1A + servoSMALLSTEP <= servoMAX) {
OCR1A += servoSMALLSTEP;
}
}
if (adc1_avg1 <= 470) { // when green sensor touched directly, servo's move tail right
if (OCR1A - servoSMALLSTEP >= servoMIN) {
OCR1A -= servoSMALLSTEP;
}
}