From 978be20b0380f76d77269446695c8dfabc847f83 Mon Sep 17 00:00:00 2001 From: EmaMaker Date: Sun, 29 Nov 2020 23:15:46 +0100 Subject: [PATCH] update ball_read to use registers instead of pinMode and digitalWrite also move all the files relative to 32u4 uC inside a dedicated folder add the Blink script i made to test if everything was working and to test registers for LEDs --- utility/32u4/Blink/Blink.ino | 36 +++++++++++++++++++ .../sketch_jan26b}/sketch_jan26b.ino | 12 +++---- .../Teensy-32u4/Teensy32U4/.gitignore | 0 .../Teensy-32u4/Teensy32U4/.travis.yml | 0 .../Teensy32U4/.vscode/extensions.json | 7 ++++ .../Teensy32U4/.vscode/settings.json | 0 .../Teensy-32u4/Teensy32U4/include/README | 0 .../Teensy-32u4/Teensy32U4/lib/README | 0 .../Teensy-32u4/Teensy32U4/platformio.ini | 0 .../Teensy-32u4/Teensy32U4/src/main.cpp | 0 .../Teensy-32u4/Teensy32U4/test/README | 0 .../ball_read/ball_read.ino | 34 ++++++++++++++---- .../Teensy32U4/.vscode/extensions.json | 7 ---- 13 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 utility/32u4/Blink/Blink.ino rename utility/{Teensy-32u4/32u4_script => 32u4/Teensy-32u4/32u4_script/sketch_jan26b}/sketch_jan26b.ino (88%) rename utility/{ => 32u4}/Teensy-32u4/Teensy32U4/.gitignore (100%) rename utility/{ => 32u4}/Teensy-32u4/Teensy32U4/.travis.yml (100%) create mode 100644 utility/32u4/Teensy-32u4/Teensy32U4/.vscode/extensions.json rename utility/{ => 32u4}/Teensy-32u4/Teensy32U4/.vscode/settings.json (100%) rename utility/{ => 32u4}/Teensy-32u4/Teensy32U4/include/README (100%) rename utility/{ => 32u4}/Teensy-32u4/Teensy32U4/lib/README (100%) rename utility/{ => 32u4}/Teensy-32u4/Teensy32U4/platformio.ini (100%) rename utility/{ => 32u4}/Teensy-32u4/Teensy32U4/src/main.cpp (100%) rename utility/{ => 32u4}/Teensy-32u4/Teensy32U4/test/README (100%) rename utility/{ball_read => 32u4}/ball_read/ball_read.ino (82%) delete mode 100644 utility/Teensy-32u4/Teensy32U4/.vscode/extensions.json diff --git a/utility/32u4/Blink/Blink.ino b/utility/32u4/Blink/Blink.ino new file mode 100644 index 0000000..7dfc3a5 --- /dev/null +++ b/utility/32u4/Blink/Blink.ino @@ -0,0 +1,36 @@ +/*For some reason in our board, which I've been explained but I'm not capable of explaining it again, including LED1 and LED4 being part of usb serial, +we can't use plain pinMode and digitalWrite on those pins (at least the output ones, for what I've tried so far), so we gotta use registers and modify them manually +While this is a bit of a PITA, runs faster on the the uC +Also using Arduino Micro bootloader, seems to work fine +If Arduino Micro bl doesn't appear to work right, try the Sparkfun ProMicro ones + +-EmaMaker 29/11/2020 22:47 CET +*/ + + +// the setup function runs once when you press reset or power the board +void setup() { + //LED3(PB7) and LED4 (PB0) + DDRB=0b10000001; + //LED2 (PF0) + DDRF=0b00000001; + //LED1 (PD5) + DDRD=0b00100000; +} + +// the loop function runs over and over again forever +void loop() { + //Set the pins HIGH, using OR the pins we don't care about are not touched + PORTB = PORTB | 0b10000001; + PORTF = PORTF | 0b00000001; + PORTD = PORTD | 0b00100000; + + delay(1000); + + //Set the pins LOW, using AND the pins we don't care about are not touched + PORTB = PORTB & 0b01111110; + PORTF = PORTF & 0b01111110; + PORTD = PORTD & 0b11011111; + + delay(1000); +} diff --git a/utility/Teensy-32u4/32u4_script/sketch_jan26b.ino b/utility/32u4/Teensy-32u4/32u4_script/sketch_jan26b/sketch_jan26b.ino similarity index 88% rename from utility/Teensy-32u4/32u4_script/sketch_jan26b.ino rename to utility/32u4/Teensy-32u4/32u4_script/sketch_jan26b/sketch_jan26b.ino index 5b0a884..3a918b6 100644 --- a/utility/Teensy-32u4/32u4_script/sketch_jan26b.ino +++ b/utility/32u4/Teensy-32u4/32u4_script/sketch_jan26b/sketch_jan26b.ino @@ -1,8 +1,8 @@ #define BTN0 A3 #define BTN1 A4 #define BTN2 A5 -#define LED_Y 11 -#define LED_R 17 +#define LED_Y 41 +#define LED_R 22 void setup (){ Serial1.begin(19200); @@ -20,10 +20,10 @@ void loop () { //We have three config. buttons, making a packet out of a single byte with a start header, so teensy can use it as it wants //The header is signed by the two most important bits put high, so 128+64 in OR with other bits shifted by the needed ammount //This approach only admits 5 configuration buttons, it should be enough - b = 0b11000000; - b |= digitalRead(BTN0); - b |= digitalRead(BTN1) << 1; - b |= digitalRead(BTN2) << 2; + b = 0b11000111; + //b |= digitalRead(BTN0); + //b |= digitalRead(BTN1) << 1; + //b |= digitalRead(BTN2) << 2; if(oldB != b) Serial1.write(b); oldB = b; diff --git a/utility/Teensy-32u4/Teensy32U4/.gitignore b/utility/32u4/Teensy-32u4/Teensy32U4/.gitignore similarity index 100% rename from utility/Teensy-32u4/Teensy32U4/.gitignore rename to utility/32u4/Teensy-32u4/Teensy32U4/.gitignore diff --git a/utility/Teensy-32u4/Teensy32U4/.travis.yml b/utility/32u4/Teensy-32u4/Teensy32U4/.travis.yml similarity index 100% rename from utility/Teensy-32u4/Teensy32U4/.travis.yml rename to utility/32u4/Teensy-32u4/Teensy32U4/.travis.yml diff --git a/utility/32u4/Teensy-32u4/Teensy32U4/.vscode/extensions.json b/utility/32u4/Teensy-32u4/Teensy32U4/.vscode/extensions.json new file mode 100644 index 0000000..0f0d740 --- /dev/null +++ b/utility/32u4/Teensy-32u4/Teensy32U4/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/utility/Teensy-32u4/Teensy32U4/.vscode/settings.json b/utility/32u4/Teensy-32u4/Teensy32U4/.vscode/settings.json similarity index 100% rename from utility/Teensy-32u4/Teensy32U4/.vscode/settings.json rename to utility/32u4/Teensy-32u4/Teensy32U4/.vscode/settings.json diff --git a/utility/Teensy-32u4/Teensy32U4/include/README b/utility/32u4/Teensy-32u4/Teensy32U4/include/README similarity index 100% rename from utility/Teensy-32u4/Teensy32U4/include/README rename to utility/32u4/Teensy-32u4/Teensy32U4/include/README diff --git a/utility/Teensy-32u4/Teensy32U4/lib/README b/utility/32u4/Teensy-32u4/Teensy32U4/lib/README similarity index 100% rename from utility/Teensy-32u4/Teensy32U4/lib/README rename to utility/32u4/Teensy-32u4/Teensy32U4/lib/README diff --git a/utility/Teensy-32u4/Teensy32U4/platformio.ini b/utility/32u4/Teensy-32u4/Teensy32U4/platformio.ini similarity index 100% rename from utility/Teensy-32u4/Teensy32U4/platformio.ini rename to utility/32u4/Teensy-32u4/Teensy32U4/platformio.ini diff --git a/utility/Teensy-32u4/Teensy32U4/src/main.cpp b/utility/32u4/Teensy-32u4/Teensy32U4/src/main.cpp similarity index 100% rename from utility/Teensy-32u4/Teensy32U4/src/main.cpp rename to utility/32u4/Teensy-32u4/Teensy32U4/src/main.cpp diff --git a/utility/Teensy-32u4/Teensy32U4/test/README b/utility/32u4/Teensy-32u4/Teensy32U4/test/README similarity index 100% rename from utility/Teensy-32u4/Teensy32U4/test/README rename to utility/32u4/Teensy-32u4/Teensy32U4/test/README diff --git a/utility/ball_read/ball_read/ball_read.ino b/utility/32u4/ball_read/ball_read.ino similarity index 82% rename from utility/ball_read/ball_read/ball_read.ino rename to utility/32u4/ball_read/ball_read.ino index f3629cc..06576ad 100644 --- a/utility/ball_read/ball_read/ball_read.ino +++ b/utility/32u4/ball_read/ball_read.ino @@ -45,6 +45,16 @@ #define BROKEN 300 #define TOO_LOW 60 +#define LED1ON (PORTD = PORTD | 0b00100000) +#define LED1OFF (PORTD & 0b11011111) +#define LED2ON (PORTD = PORTD | 0b00100000) +#define LED2OFF (PORTF & 0b01111110) +#define LED3ON (PORTB | 0b10000000) +#define LED3OFF (PORTB & 0b01111111) +#define LED4ON (PORTB | 0b00000001) +#define LED4OFF (PORTB & 0b11111110) + + int counter[16]; int distance; int nmax = 0; @@ -64,13 +74,13 @@ byte sendAngle = 0, sendDistance = 0; byte sendByte = 0; unsigned long t = 0; -t + void setup() { delay(1000); Serial.begin(57600); - pinMode(26, INPUT); //S1 + /*pinMode(26, INPUT); //S1 pinMode(25, INPUT); //S2 pinMode(19, INPUT); //S3 pinMode(18, INPUT); //S4 @@ -85,9 +95,21 @@ void setup() { pinMode(30, INPUT); //S13 pinMode(29, INPUT); //S14 pinMode(28, INPUT); //S15 - pinMode(27, INPUT); //S16 + pinMode(27, INPUT); //S16*/ - pinMode(22, OUTPUT); //LED1 + /*For now replace pinMode with writes to the direction register. + We don't know if pinMode will work on those sensors, and it has proven not be working on digitalWrite for reasons probably relative to compatibility between Arduino and our board, + but this needs further investigation*/ + + //Set the LEDs as outputs, keep the rest as input by default + + //LED3(PB7) and LED4 (PB0) + DDRB=0b10000001; + //LED2 (PF0) + DDRF=0b00000001; + //LED1 (PD5) + DDRD=0b00100000; + DDRE = 0b00000000; for (int i = 0; i < 16; i++) { xs[i] = cos((22.5 * PI / 180) * i); @@ -153,9 +175,9 @@ void readBallInterpolation() { //turn led on if (dist == 0) { - digitalWrite(22, LOW); + LED1ON; } else { - digitalWrite(22, HIGH); + LED1OFF; } } diff --git a/utility/Teensy-32u4/Teensy32U4/.vscode/extensions.json b/utility/Teensy-32u4/Teensy32U4/.vscode/extensions.json deleted file mode 100644 index 272828b..0000000 --- a/utility/Teensy-32u4/Teensy32U4/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} \ No newline at end of file