the following sketch expands on standard blink concept including
basics of led pin wiggling, button input using gertboard button paradigm,
, including serial comm interface monitoring process; well,
giving avr commands (which affect avr coding!)
in pic above, powering gertboard pi 5v (pin2) , ground
(pin39); piggy-backing on 5v fan pin connectors.
avr jtag connectors connected pi spi pins @ center of
gpio port (gp8, gp9, gp10, gp11).
i'm running avr outputs (13, 12, 11, 10) off-board because ran out of
ff connectors! if i'd had enough connectors might have used gertboard
leds...
gertboard buttons 1 , 2 on red , yellow cable @ center of the
board , connect avr pins 2 , 3 respectively. have output jumpers
attached @ channel 1 , 2 (optionally) visual indicator on my
button presses (for debugging).
green , purple cable @ center of board serial cable running
pi gpio14 , gpio15 pins, allow serial comm interface avr.
following code counter.ino sketch coding fun
(and if else wants screw around that's too).
sketch loop() has 2 phases... 1) 4 leds blink binary succession
0x0-0xf (the high-low order selected serial console command or
button press); , 2) 4 leds wiggle during time
avr in serial command mode.
reset can selected during counter mode while leds in binary
succession button 1. button 2 reverse high-low order blinking
of binary led display.
during binary led display counting following serial commands accepted:
'h' keypress -- 'hello, world'
'r' keypress -- avr cycle counter reset request
'l' keypress -- 'led counter = <current counter>'
's' keypress -- avr led counter high-low order swap request
warning: worth, while running popped j7 3v3
jumper off gertboard make input switch connections. doing
created kind or surge on 5v current , poly fuse on
pi tripped! red light went out, , although pi did not crash
(unbelievably) 5v dropped 4.18 volts. returned normal
following day, after poly fuse healed.
note: board fun play with; , think highly useful. indeed
thankful gert van loo developement of board, , gordon @ drogon
software updates make arduino ide work pi , the
gertboard (very nice piece of engineering, both guys-- rock!)
basics of led pin wiggling, button input using gertboard button paradigm,
, including serial comm interface monitoring process; well,
giving avr commands (which affect avr coding!)
in pic above, powering gertboard pi 5v (pin2) , ground
(pin39); piggy-backing on 5v fan pin connectors.
avr jtag connectors connected pi spi pins @ center of
gpio port (gp8, gp9, gp10, gp11).
i'm running avr outputs (13, 12, 11, 10) off-board because ran out of
ff connectors! if i'd had enough connectors might have used gertboard
leds...
gertboard buttons 1 , 2 on red , yellow cable @ center of the
board , connect avr pins 2 , 3 respectively. have output jumpers
attached @ channel 1 , 2 (optionally) visual indicator on my
button presses (for debugging).
green , purple cable @ center of board serial cable running
pi gpio14 , gpio15 pins, allow serial comm interface avr.
following code counter.ino sketch coding fun
(and if else wants screw around that's too).
code: select all
/* counter.ino 4 bit binary counter serial interface mark h. harris 5-29-2016 v0.02j */ int nochar= -1; int esc= 27; int false=0; int true=1; int count=0; // avr cycle counter int button1=2; // resets cycle counter int button2=3; // reverses high-order low-order led counter int button3=4; // sets avr in sleep mode char keyin; // serial command character input int pins[4] = {13, 12, 11, 10}; int rev[4] = {1, 2, 4, 8}; // pin 10 high-order int fwd[4] = {8, 4, 2, 1}; // pin 13 high-order int* fwdrev = fwd; // bin_display() digits int swap_flag = false; // high-order low-order reversed int button1_flag=false; // count reset request pending int button2_flag=false; // swap request pending int button3_flag=false; // sleep mode request pending int button4_flag=false; // wiggle mode request pending int button5_flag=false; // flash mode request pending int button6_flag=false; // scanner mode request pending int button7_flag=false; // strobe mode request pending int button8_flag=false; // license display request pending int button9_flag=false; // commands menu request pending void setup() { int = 0; (i=0; i<=3; i++) { pinmode(pins[i], output); } pinmode(button1, input); pinmode(button2, input); serial.begin(9600); digitalwrite(button1, high); // button pullup digitalwrite(button2, high); // button pullup digitalwrite(button3, high); // button pullup } void loop() { int i=0; int j=0; button1_flag=false; button2_flag=false; (i=0; i<=15; i++) { bin_display(i, pins, fwdrev); // led counter display keyin=serial.read(); // request commands serially if (keyin=='h') { // page 1 commands menu keyin=help_menu(pins, fwdrev); button9_flag=true; } if (keyin=='h') { // page 2 commands menu keyin=help_menu_2(pins, fwdrev); button9_flag=true; } if (keyin=='l') { keyin=dsp_license(pins, fwdrev); button8_flag=true; } if (!digitalread(button1) && !button1_flag) { serial.println("avr cycle counter reset button"); button1_flag=true; } if (!digitalread(button2) && !button2_flag) { serial.println("avr orientation swap button"); button2_flag=true; } if (keyin=='q' || keyin=='q') { serial.println("avr sleep_mode request"); button3_flag=true; } if (keyin=='w' || keyin=='w') { serial.println("avr wiggle mode request"); button4_flag=true; } if (keyin=='f' || keyin=='f') { serial.println("avr flash mode request"); button5_flag=true; } if (keyin=='z' || keyin=='z') { serial.println("avr scanner mode request"); button6_flag=true; } if (keyin=='b' || keyin=='b') { serial.println("avr strobe mode request"); button7_flag=true; } delay(198); if (button8_flag || button9_flag) break; } bin_display(0x0, pins, fwdrev); delay(770); (i=0; i<=7; i++) { keyin=serial.read(); // process pending requests if (button3_flag) { sleep_mode(pins); button3_flag=false; } if (button4_flag) { wiggle(pins, fwdrev); button4_flag=false; } if (button5_flag) { flash(pins, fwdrev); button5_flag=false; } if (button6_flag) { scanner(pins, fwdrev); button6_flag=false; } if (button7_flag) { strobe(pins, fwdrev); button7_flag=false; } bin_display(0xa, pins, fwdrev); delay(128); bin_display(0x5, pins, fwdrev); delay(128); if (keyin=='r' || button1_flag) { serial.println("avr cycle counter reset command"); count=0; button1_flag=false; } if (keyin=='s' || button2_flag) { serial.println("avr binary orientation swap command"); button2_flag=false; if (swap_flag) { fwdrev = fwd; swap_flag = false; } else { fwdrev = rev; swap_flag = true; } if (fwdrev==fwd) { (j=0; j<=3; j++) { serial.print(pins[j]); serial.print(", "); } serial.println(); } else { (j=3; j>=0; j--) { serial.print(pins[j]); serial.print(", "); } serial.println(); } } } count+=1; serial.print("avr cycle counter "); serial.println(count); button1_flag=false; button2_flag=false; button8_flag=false; button9_flag=false; if (!digitalread(button3)) sleep_mode(pins); } // binary led display function void bin_display(int val, int pins[], int digits[]) { int n=0; (n=0; n<=3; n++) { if (val & digits[n]) digitalwrite(pins[n], high); else digitalwrite(pins[n], low); } } void sleep_mode(int pins[]) { int keyin; int i; (i=0; i<=3; i++) { digitalwrite(pins[i], low); } while (true) { (i=7; i<=245; i++) { analogwrite(10, i); delay(4); } keyin = serial.read(); if (keyin=='x' || keyin==esc) break; if (!digitalread(button1)) wiggle(pins, fwd); if (!digitalread(button2)) scanner(pins, fwd); (i=245; i>=7; i--) { analogwrite(10, i); delay(4); } keyin = serial.read(); if (keyin=='x' || keyin==esc || !digitalread(button3)) break; delay(70); if (!digitalread(button1)) flash(pins, fwd); if (!digitalread(button2)) strobe(pins, fwd); } } void wiggle(int pins[], int digits[]) { int keyin; while (true) { bin_display(0xc, pins, digits); delay(127); bin_display(0x6, pins, digits); delay(127); bin_display(0x3, pins, digits); delay(127); bin_display(0x6, pins, digits); delay(120); keyin = serial.read(); if (keyin=='x' || keyin==esc || !digitalread(button1)) break; } bin_display(0x0, pins, digits); } void flash(int pins[], int digits[]) { int keyin; while (true) { bin_display(0xf, pins, digits); delay(256); bin_display(0x0, pins, digits); delay(250); keyin = serial.read(); if (keyin=='x' || keyin==esc || !digitalread(button1)) break; } bin_display(0x0, pins, digits); } void scanner(int pins[], int digits[]) { int keyin; int t_delay=128; while (true) { bin_display(0x8, pins, digits); delay(t_delay); bin_display(0x4, pins, digits); delay(t_delay); bin_display(0x2, pins, digits); delay(t_delay); bin_display(0x1, pins, digits); delay(t_delay); bin_display(0x2, pins, digits); delay(t_delay); bin_display(0x4, pins, digits); delay(t_delay-7); keyin = serial.read(); if (keyin=='x' || keyin==esc || !digitalread(button1)) break; } bin_display(0x0, pins, digits); } void strobe(int pins[], int digits[]) { int keyin; while (true) { bin_display(0x8, pins, digits); delay(47); bin_display(0x4, pins, digits); delay(47); bin_display(0x2, pins, digits); delay(47); bin_display(0x1, pins, digits); delay(47); bin_display(0x0, pins, digits); delay(27); keyin = serial.read(); if (keyin=='x' || keyin==esc || !digitalread(button1)) break; } bin_display(0x0, pins, digits); } int help_menu(int pins[], int digits[]) { int i; char keyin; bin_display(0x0, pins, digits); (i=0; i<=24; i++) { serial.println(); } serial.println(" ***********************************************"); serial.println(" ** commands menu **"); serial.println(" ***********************************************"); serial.println(" ** 'b' -- strobe **"); serial.println(" ** 'w' -- wiggle **"); serial.println(" ** 'z' -- scanner **"); serial.println(" ** 'f' -- flasher **"); serial.println(" ** 'h' -- (help menu page 2) **"); serial.println(" ** 'l' -- license **"); serial.println(" ** 'q' -- quiescense sleep **"); serial.println(" ** 'x' -- exit counter **"); serial.println(" ***********************************************"); (i=0; i<=7; i++) { serial.println(); } while (true) { if (int(keyin=serial.read())!= nochar) break; delay(256); } (i=0; i<=24; i++) { serial.println(); } return keyin; } int help_menu_2(int pins[], int digits[]) { int i; char keyin; bin_display(0x0, pins, digits); (i=0; i<=24; i++) { serial.println(); } serial.println(" ***********************************************"); serial.println(" ** commands information **"); serial.println(" ***********************************************"); serial.println(" ** (2) led flasher command mode **"); serial.println(" ** **"); serial.println(" ** 'r' -- avr cycle counter reset **"); serial.println(" ** 's' -- avr binary high-low order swap **"); serial.println(" ** **"); serial.println(" ** **"); serial.println(" ** (press key) **"); serial.println(" ** **"); serial.println(" ***********************************************"); (i=0; i<=7; i++) { serial.println(); } while (true) { if (int(keyin=serial.read())!= nochar) break; delay(256); } (i=0; i<=24; i++) { serial.println(); } return keyin; } int dsp_license(int pins[], int digits[]) { int i; char keyin; bin_display(0x0, pins, digits); (i=0; i<=24; i++) { serial.println(); } serial.println(" ***********************************************"); serial.println(" ** counter license **"); serial.println(" ***********************************************"); serial.println(" ** **"); serial.println(" ** mark h. harris **"); serial.println(" ** v.02j **"); serial.println(" ** 05-28-2016 **"); serial.println(" ** **"); serial.println(" ** gplv3 licesne **"); serial.println(" ** **"); serial.println(" ** (press key) **"); serial.println(" ** **"); serial.println(" ***********************************************"); (i=0; i<=7; i++) { serial.println(); } while (true) { if (int(keyin=serial.read())!= nochar) break; delay(256); } (i=0; i<=24; i++) { serial.println(); } return keyin; }
0x0-0xf (the high-low order selected serial console command or
button press); , 2) 4 leds wiggle during time
avr in serial command mode.
reset can selected during counter mode while leds in binary
succession button 1. button 2 reverse high-low order blinking
of binary led display.
during binary led display counting following serial commands accepted:
'h' keypress -- 'hello, world'
'r' keypress -- avr cycle counter reset request
'l' keypress -- 'led counter = <current counter>'
's' keypress -- avr led counter high-low order swap request
warning: worth, while running popped j7 3v3
jumper off gertboard make input switch connections. doing
created kind or surge on 5v current , poly fuse on
pi tripped! red light went out, , although pi did not crash
(unbelievably) 5v dropped 4.18 volts. returned normal
following day, after poly fuse healed.
note: board fun play with; , think highly useful. indeed
thankful gert van loo developement of board, , gordon @ drogon
software updates make arduino ide work pi , the
gertboard (very nice piece of engineering, both guys-- rock!)
modified counter.ino demo code allow sub-command loops(), controlled via serial interface character commands during 'counter' loop phase. complete list below:markhaysharris777 wrote: 'h' keypress -- 'hello, world'
'r' keypress -- avr cycle counter reset request
'l' keypress -- 'led counter = <current counter>'
's' keypress -- avr led counter high-low order swap request
'q' keypress -- quiescence 'sleep' mode request
'w' keypress -- wiggle mode request
'f' keypress -- flash mode request
'z' keypress -- scanner mode request
'b' keypress -- strobe mode request
'x' exit sub-command loops
while counter in 'counter' loop() phase above command characters serial console cause main loop() enter sub-command loop until exit 'x' character sent.
quiescence sleep_mode() uses pwm (analogwrite) pulse pin10 while else comes halt. unlike pi (which has 1 pwm pin) avr has 6 pwm pins, under control of pi indirectly.
raspberrypi
Comments
Post a Comment