summaryrefslogtreecommitdiff
path: root/OLD_CODE_REMOVE_LATER/debug/prewk/comm
diff options
context:
space:
mode:
Diffstat (limited to 'OLD_CODE_REMOVE_LATER/debug/prewk/comm')
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/arduino_binairy_decoder/arduino_binairy_decoder.ino28
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/arduino_comm/arduino_comm.ino37
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/readme.txt.txt3
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/seeed_uart/seeed_uart.ino9
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/teensy_uard_read/teensy_uard_read.ino17
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/spi/arduino_spi_master/arduino_spi_master.ino34
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/spi/arduino_spi_slave_1.py102
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/uart/arduino_uart/arduino_uart.ino17
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/prewk/comm/uart/arduino_uart_1.py42
9 files changed, 289 insertions, 0 deletions
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/arduino_binairy_decoder/arduino_binairy_decoder.ino b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/arduino_binairy_decoder/arduino_binairy_decoder.ino
new file mode 100644
index 0000000..eb257e5
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/arduino_binairy_decoder/arduino_binairy_decoder.ino
@@ -0,0 +1,28 @@
+String inp = "01101000";
+int decimalValue = 0;
+
+void setup() {
+ Serial.begin(115200);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for native USB
+ }
+ Serial.println("");
+
+ Serial.println(inp);
+ String binary = inp.substring(2);
+ Serial.println(binary);
+ for (int i = 0; i < binary.length(); i++) {
+ // Calculate the value of the current bit
+ int bitValue = binary.charAt(i) - '0';
+ // Update the decimal value by shifting the bit to its correct position
+ decimalValue = (decimalValue << 1) | bitValue;
+ }
+ Serial.println(decimalValue);
+ Serial.println("");
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+ delay(1000);
+
+}
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/arduino_comm/arduino_comm.ino b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/arduino_comm/arduino_comm.ino
new file mode 100644
index 0000000..4a2b205
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/arduino_comm/arduino_comm.ino
@@ -0,0 +1,37 @@
+String tlocd = "";
+String locd = "";
+bool readloc = false;
+unsigned long datatime = 0;
+
+void setup() {
+ Serial1.begin(19200);
+ Serial.begin(19200);
+}
+
+void loop() {
+ if(Serial1.available()){
+ datatime = millis();
+
+ byte byteRead = Serial1.read();
+
+ if(byteRead == 's'){
+ tlocd = "";
+ readloc = true;
+ }
+ else if(byteRead == 'e'){
+ readloc = false;
+ locd = tlocd;
+ }
+ else if(readloc == true){
+ tlocd += (char)byteRead;
+ }
+ }
+ else{
+ if(millis() - datatime > 5000){
+ Serial.println("Err no data recieved for 5 sec");
+ locd = "999";
+ }
+ }
+ Serial.println(locd);
+ delay(134);
+}
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/readme.txt.txt b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/readme.txt.txt
new file mode 100644
index 0000000..ef9f996
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/readme.txt.txt
@@ -0,0 +1,3 @@
+serial communication between two Seeed Studio XIAO SAMD21 and one teensy.
+Teensy Serial 2 and 3 on read
+Seeed XIAO SAMD21 write a 8 values on Serial1 between 0-10000 (pulses from IR sensor) every 0,25 seconds. For example 100 pulses in 1 second = 00025
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/seeed_uart/seeed_uart.ino b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/seeed_uart/seeed_uart.ino
new file mode 100644
index 0000000..32750de
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/seeed_uart/seeed_uart.ino
@@ -0,0 +1,9 @@
+void setup() {
+ Serial1.begin(9600)
+
+}
+
+void loop() {
+ Serial1.println("/D:00025:/E");
+ delay(250);
+}
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/teensy_uard_read/teensy_uard_read.ino b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/teensy_uard_read/teensy_uard_read.ino
new file mode 100644
index 0000000..684c199
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/seeed-teensy/teensy_uard_read/teensy_uard_read.ino
@@ -0,0 +1,17 @@
+void setup() {
+ // Initialize Serial1 with a baud rate of 19200
+ Serial1.begin(9600);
+ Serial.begin(9600); // Initialize Serial for debugging
+}
+
+void loop() {
+ // Check if there is any data available to read from Serial1
+ if (Serial1.available()) {
+ // Read the most recent byte
+ byte byteRead = Serial1.read();
+ // Echo the value that was read
+ Serial1.write(byteRead);
+ // Print the received byte for debugging
+ Serial.print((char)byteRead);
+ }
+}
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/spi/arduino_spi_master/arduino_spi_master.ino b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/spi/arduino_spi_master/arduino_spi_master.ino
new file mode 100644
index 0000000..248ef0f
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/spi/arduino_spi_master/arduino_spi_master.ino
@@ -0,0 +1,34 @@
+#include <SPI.h>
+#define SS_PIN 10
+#define BAUD_RATE 19200
+#define CHAR_BUF 128
+
+void setup() {
+ pinMode(SS_PIN, OUTPUT);
+ Serial.begin(BAUD_RATE);
+ SPI.begin();
+ SPI.setBitOrder(MSBFIRST);
+ SPI.setClockDivider(SPI_CLOCK_DIV16);
+ SPI.setDataMode(SPI_MODE0);
+ delay(1000); // Give the OpenMV Cam time to bootup.
+}
+
+void loop() {
+ int32_t len = 0;
+ char buff[CHAR_BUF] = {0};
+ digitalWrite(SS_PIN, LOW);
+ delay(1); // Give the OpenMV Cam some time to setup to send data.
+
+ if(SPI.transfer(1) == 85) { // saw sync char?
+ SPI.transfer(&len, 4); // get length
+ if (len) {
+ SPI.transfer(&buff, min(len, CHAR_BUF));
+ len -= min(len, CHAR_BUF);
+ }
+ while (len--) SPI.transfer(0); // eat any remaining bytes
+ }
+
+ digitalWrite(SS_PIN, HIGH);
+ Serial.print(buff);
+ delay(1); // Don't loop to quickly.
+} \ No newline at end of file
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/spi/arduino_spi_slave_1.py b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/spi/arduino_spi_slave_1.py
new file mode 100644
index 0000000..e05c2f0
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/spi/arduino_spi_slave_1.py
@@ -0,0 +1,102 @@
+# This work is licensed under the MIT license.
+# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
+# https://github.com/openmv/openmv/blob/master/LICENSE
+#
+# SPI with the Arduino as the master device and the OpenMV Cam as the slave.
+#
+# Please wire up your OpenMV Cam to your Arduino like this:
+#
+# OpenMV Cam Master Out Slave In (P0) - Arduino Uno MOSI (11)
+# OpenMV Cam Master In Slave Out (P1) - Arduino Uno MISO (12)
+# OpenMV Cam Serial Clock (P2) - Arduino Uno SCK (13)
+# OpenMV Cam Slave Select (P3) - Arduino Uno SS (10)
+# OpenMV Cam Ground - Arduino Ground
+
+import pyb
+import ustruct
+import time
+
+text = "Hello World!\n"
+data = ustruct.pack("<bi%ds" % len(text), 85, len(text), text) # 85 is a sync char.
+# Use "ustruct" to build data packets to send.
+# "<" puts the data in the struct in little endian order.
+# "b" puts a signed char in the data stream.
+# "i" puts a signed integer in the data stream.
+# "%ds" puts a string in the data stream. E.g. "13s" for "Hello World!\n" (13 chars).
+# See https://docs.python.org/3/library/struct.html
+
+# READ ME!!!
+#
+# Please understand that when your OpenMV Cam is not the SPI master it may miss responding to
+# sending data as a SPI slave no matter if you call "spi.send()" in an interrupt callback or in the
+# main loop below. Because of this you must absolutely design your communications protocol such
+# that if the slave device (the OpenMV Cam) doesn't call "spi.send()" in time that garbage data
+# read from the SPI peripheral by the master (the Arduino) is tossed. To accomplish this we use a
+# sync character of 85 (binary 01010101) which the Arduino will look for as the first byte read.
+# If it doesn't see this then it aborts the SPI transaction and will try again. Second, in order to
+# clear out the SPI peripheral state we always send a multiple of four bytes and an extra four zero
+# bytes to make sure that the SPI peripheral doesn't hold any stale data which could be 85. Note
+# that the OpenMV Cam will miss the "spi.send()" window randomly because it has to service
+# interrupts. Interrupts will happen a lot more while connected to your PC.
+
+# The hardware SPI bus for your OpenMV Cam is always SPI bus 2.
+# polarity = 0 -> clock is idle low.
+# phase = 0 -> sample data on rising clock edge, output data on falling clock edge.
+spi = pyb.SPI(2, pyb.SPI.SLAVE, polarity=0, phase=0)
+
+
+# NSS callback.
+def nss_callback(line):
+ global spi, data
+ try:
+ spi.send(data, timeout=1000)
+ except OSError as err:
+ pass # Don't care about errors - so pass.
+ # Note that there are 3 possible errors. A timeout error, a general purpose error, or
+ # a busy error. The error codes are 116, 5, 16 respectively for "err.arg[0]".
+
+
+# Configure NSS/CS in IRQ mode to send data when requested by the master.
+pyb.ExtInt(pyb.Pin("P3"), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, nss_callback)
+
+while True:
+ time.sleep_ms(1000)
+
+###################################################################################################
+# Arduino Code
+###################################################################################################
+#
+# #include <SPI.h>
+# #define SS_PIN 10
+# #define BAUD_RATE 19200
+# #define CHAR_BUF 128
+#
+# void setup() {
+# pinMode(SS_PIN, OUTPUT);
+# Serial.begin(BAUD_RATE);
+# SPI.begin();
+# SPI.setBitOrder(MSBFIRST);
+# SPI.setClockDivider(SPI_CLOCK_DIV16);
+# SPI.setDataMode(SPI_MODE0);
+# delay(1000); // Give the OpenMV Cam time to bootup.
+# }
+#
+# void loop() {
+# int32_t len = 0;
+# char buff[CHAR_BUF] = {0};
+# digitalWrite(SS_PIN, LOW);
+# delay(1); // Give the OpenMV Cam some time to setup to send data.
+#
+# if(SPI.transfer(1) == 85) { // saw sync char?
+# SPI.transfer(&len, 4); // get length
+# if (len) {
+# SPI.transfer(&buff, min(len, CHAR_BUF));
+# len -= min(len, CHAR_BUF);
+# }
+# while (len--) SPI.transfer(0); // eat any remaining bytes
+# }
+#
+# digitalWrite(SS_PIN, HIGH);
+# Serial.print(buff);
+# delay(1); // Don't loop to quickly.
+# }
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/uart/arduino_uart/arduino_uart.ino b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/uart/arduino_uart/arduino_uart.ino
new file mode 100644
index 0000000..6385695
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/uart/arduino_uart/arduino_uart.ino
@@ -0,0 +1,17 @@
+void setup() {
+ // Initialize Serial1 with a baud rate of 19200
+ Serial1.begin(19200);
+ Serial.begin(19200); // Initialize Serial for debugging
+}
+
+void loop() {
+ // Check if there is any data available to read from Serial1
+ if (Serial1.available()) {
+ // Read the most recent byte
+ byte byteRead = Serial1.read();
+ // Echo the value that was read
+ Serial1.write(byteRead);
+ // Print the received byte for debugging
+ Serial.print((char)byteRead);
+ }
+}
diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/comm/uart/arduino_uart_1.py b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/uart/arduino_uart_1.py
new file mode 100644
index 0000000..3996cf7
--- /dev/null
+++ b/OLD_CODE_REMOVE_LATER/debug/prewk/comm/uart/arduino_uart_1.py
@@ -0,0 +1,42 @@
+# This work is licensed under the MIT license.
+# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
+# https://github.com/openmv/openmv/blob/master/LICENSE
+#
+# Basic UART communications between OpenMV and Arduino Uno.
+
+# 1) Wire up your OpenMV Cam to your Arduino Uno like this:
+#
+# OpenMV Cam Ground Pin ----> Arduino Ground
+# OpenMV Cam UART3_TX(P4) ----> Arduino Uno UART_RX(0)
+# OpenMV Cam UART3_RX(P5) ----> Arduino Uno UART_TX(1)
+
+# 2) Uncomment and upload the following sketch to Arduino:
+#
+# void setup() {
+# // put your setup code here, to run once:
+# Serial.begin(19200);
+# }
+#
+# void loop() {
+# // put your main code here, to run repeatedly:
+# if (Serial.available()) {
+# // Read the most recent byte
+# byte byteRead = Serial.read();
+# // ECHO the value that was read
+# Serial.write(byteRead);
+# }
+# }
+
+# 3) Run the following script in OpenMV IDE:
+
+import time
+from pyb import UART
+
+# UART 3, and baudrate.
+uart = UART(3, 19200, timeout_char=200)
+
+while True:
+ uart.write("Hello World!\n")
+ if uart.any():
+ print(uart.read())
+ time.sleep_ms(1000)