summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbel Tim <abel@main.home>2024-06-02 17:57:32 +0200
committerAbel Tim <abel@main.home>2024-06-02 17:57:32 +0200
commit6671a64563369d8e3540639753ba64086a75d7a3 (patch)
tree7bb8a4dc198773c517ac2148e7e051be1f76aaba
parentb6bdab63c9902604a74a7b4b996bdd0dc7614454 (diff)
downloadrobotica-6671a64563369d8e3540639753ba64086a75d7a3.tar.gz
robotica-6671a64563369d8e3540639753ba64086a75d7a3.zip
add files
-rw-r--r--lower_connection_schema.pdfbin0 -> 129143 bytes
-rw-r--r--spi_comm/arduino_binairy_decoder/arduino_binairy_decoder.ino28
-rw-r--r--spi_comm/arduino_master_read/arduino_master_read.ino26
-rw-r--r--spi_comm/arduino_slave_read/arduino_slave_read.ino30
-rw-r--r--spi_comm/arduino_slave_write/arduino_slave_write.ino34
-rw-r--r--spi_comm/deg_to_byte.py5
-rw-r--r--spi_comm/openmv_slave/spi_com_master.py36
-rw-r--r--upper_connection_schema.pdfbin0 -> 168395 bytes
8 files changed, 159 insertions, 0 deletions
diff --git a/lower_connection_schema.pdf b/lower_connection_schema.pdf
new file mode 100644
index 0000000..704a16c
--- /dev/null
+++ b/lower_connection_schema.pdf
Binary files differ
diff --git a/spi_comm/arduino_binairy_decoder/arduino_binairy_decoder.ino b/spi_comm/arduino_binairy_decoder/arduino_binairy_decoder.ino
new file mode 100644
index 0000000..eb257e5
--- /dev/null
+++ b/spi_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/spi_comm/arduino_master_read/arduino_master_read.ino b/spi_comm/arduino_master_read/arduino_master_read.ino
new file mode 100644
index 0000000..e31eac9
--- /dev/null
+++ b/spi_comm/arduino_master_read/arduino_master_read.ino
@@ -0,0 +1,26 @@
+#include <SPI.h>
+
+int x;
+
+void setup() {
+ Serial.begin(115200);
+ SPI.begin();
+ SPI.setClockDivider(SPI_CLOCK_DIV8);
+ digitalWrite(SS,HIGH);
+
+}
+
+void loop() {
+ byte Mastersend,Mastereceive;
+ digitalWrite(SS, LOW);
+ x = 1;
+ Mastersend = x;
+ Mastereceive=SPI.transfer(Mastersend);
+ if(Mastereceive == 1){
+ Serial.println("Master receive 1");
+ }
+ else{
+ Serial.println("Master receive 0");
+ }
+
+}
diff --git a/spi_comm/arduino_slave_read/arduino_slave_read.ino b/spi_comm/arduino_slave_read/arduino_slave_read.ino
new file mode 100644
index 0000000..8264ae3
--- /dev/null
+++ b/spi_comm/arduino_slave_read/arduino_slave_read.ino
@@ -0,0 +1,30 @@
+#include<SPI.h>
+
+volatile boolean received;
+volatile byte receivedData;
+
+ISR (SPI_STC_vect) //Inerrrput routine function
+{
+ receivedData = SPDR; // Get the received data from SPDR register
+ received = true; // Sets received as True
+}
+
+void setup()
+{
+ Serial.begin(115200);
+
+ pinMode(MISO,OUTPUT); //Sets MISO as OUTPUT
+ SPCR |= _BV(SPE); //Turn on SPI in Slave Mode
+ received = false;
+ SPI.attachInterrupt(); //Activate SPI Interuupt
+}
+
+
+void loop()
+{
+ if(received) {
+ SPDR = receivedData; // send back the received data, this is not necessary, only for demo purpose
+ received = false;
+ Serial.print(receivedData, HEX);
+ }
+}
diff --git a/spi_comm/arduino_slave_write/arduino_slave_write.ino b/spi_comm/arduino_slave_write/arduino_slave_write.ino
new file mode 100644
index 0000000..d6f838f
--- /dev/null
+++ b/spi_comm/arduino_slave_write/arduino_slave_write.ino
@@ -0,0 +1,34 @@
+#include <SPI.h>
+
+int x;
+long randNumber;
+
+
+volatile boolean received;
+volatile byte Slavereceived,Slavesend;
+
+void setup() {
+ Serial.begin(115200);
+ randomSeed(analogRead(0));
+
+ pinMode(MISO,OUTPUT);
+ SPCR |= _BV(SPE);
+ received = false;
+ SPI.attachInterrupt();
+
+}
+
+ISR (SPI_STC_vect){
+ Slavereceived = SPDR;
+ received = true;
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+ randNumber = random(0, 1);
+ Serial.println(randNumber);
+ Slavesend=randNumber;
+ SPDR = Slavesend;
+ delay(1000);
+
+}
diff --git a/spi_comm/deg_to_byte.py b/spi_comm/deg_to_byte.py
new file mode 100644
index 0000000..196d4a5
--- /dev/null
+++ b/spi_comm/deg_to_byte.py
@@ -0,0 +1,5 @@
+deg = 40
+sbinary = format(deg, 'b')
+print(sbinary)
+binary = "".join(("01", sbinary))
+print(binary) \ No newline at end of file
diff --git a/spi_comm/openmv_slave/spi_com_master.py b/spi_comm/openmv_slave/spi_com_master.py
new file mode 100644
index 0000000..6e10881
--- /dev/null
+++ b/spi_comm/openmv_slave/spi_com_master.py
@@ -0,0 +1,36 @@
+from machine import SPI, Pin
+deg = 40
+binary = format(deg, 'b')
+print(binary)
+
+spi = SPI(0, baudrate=400000) # Create SPI peripheral 0 at frequency of 400kHz.
+ # Depending on the use case, extra parameters may be required
+ # to select the bus characteristics and/or pins to use.
+cs = Pin(4, mode=Pin.OUT, value=1) # Create chip-select on pin 4.
+
+try:
+ cs(0) # Select peripheral.
+ spi.write(b"12345678") # Write 8 bytes, and don't care about received data.
+finally:
+ cs(1) # Deselect peripheral.
+
+try:
+ cs(0) # Select peripheral.
+ rxdata = spi.read(8, 0x42) # Read 8 bytes while writing 0x42 for each byte.
+finally:
+ cs(1) # Deselect peripheral.
+
+rxdata = bytearray(8)
+try:
+ cs(0) # Select peripheral.
+ spi.readinto(rxdata, 0x42) # Read 8 bytes inplace while writing 0x42 for each byte.
+finally:
+ cs(1) # Deselect peripheral.
+
+txdata = b"12345678"
+rxdata = bytearray(len(txdata))
+try:
+ cs(0) # Select peripheral.
+ spi.write_readinto(txdata, rxdata) # Simultaneously write and read bytes.
+finally:
+ cs(1) # Deselect peripheral.
diff --git a/upper_connection_schema.pdf b/upper_connection_schema.pdf
new file mode 100644
index 0000000..490a60f
--- /dev/null
+++ b/upper_connection_schema.pdf
Binary files differ