Read input value on switch from ATtiny1614¶
What’s this ?¶
Testing how I can “read” data from Serial communication on browser.
Materials¶
- ATtiny1614 buzzer board (w/LED, tact switch and buzzer)
- USB-FTDI Serial converter board
- FTDI-SErial UPDI-3pin converter
- USB Cable
- Laptop PC (Macbook Pro)
Problem¶
Warning
I wanted to use analogRead() with pwm pin, but my 3216 breakout board was broken and my 1614 board does not have pwm input. Instead, I used digitalRead() by tactile switch and convert transmitting values by some logics.
How to read serial value?¶
- Serial monitor
- Serial Plotter
- Python (tkinter)
- Processing
- Browser (Web serial API + p5.js)
1. Serial monitor¶
Arduiono IDE > Tool > Serial monitor
Set baud rate as you set on Arduino code (e.g.Serial.begin(9600)
)
2. Serial plotter¶
Arduiono IDE > Tool > Serial plotter Plotter visualize by time sequence.
- t1614_fade_blink01.ino
- LED blinks 3 times by interval time. Interval time is set by pushing tactile switch)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
Outcome (Serial plotter)¶
3. Python (tkinter)¶
Tweaked python interface samples by Neil (Ref. FabAcademy - input devices)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
t1614_switch_tk.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
Outcome (python tkinter)¶
4. Processing¶
Processing: t1614_fade_blink02_read.pde
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Outcome (Processing)¶
5. Browser (Web serial API + p5.js)¶
- Arduino: t1614_Web-serial-api_sample.ino
- Write and read valude over serial
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
Browser configuration:
- On Chrome browser, set url as chrome://flags/#enable-experimental-web-platform-features
and “Enable” it.
Following index.htm
, sketch.js
and style.css
is on p5.js.
Ref. Let Arduino Control Your Browser
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
I needed to change “baudrate” on sample to “baudRate”.
sketch.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
style.css
1 2 3 4 5 6 7 |
|
Outcome (Web Serial APi)¶
References¶
- SpenceKonde - ATtiny 416/816/1616/3216
- create.arduino.cc - Let Arduino Control Your Browser
- ArduinoとProcessingを連携させてシリアルデータをやり取りする
- ProcessingとArduinoでシリアル通信する方法