Send long array to arduino through serial processing port

So, I build a 24x16 (height 16, length 24) LED matrix and use Arduino Uno to control it. This is only one color matrix, and I use an array to store all data bits.

This is an example of how I store data on arduino:

long frame [16] = {11184810, 5592405, 11184810, 5592405, 11184810, 5592405, 11184810, 5592405, 11184810, 5592405, 11184810, 5592405, 11184810, 5592405, 11184810, 5592405};

The method of storing this data is carried out row by row. ex: long frame [16] = {line 1 bit, line 2 bits, ... etc.}

If you convert 11184810 to binary; You will receive 1010101010101010101010101010, which represents data for one row of LEDs.

The only restriction that I encountered when using arduino was the limited space on it for storing abstract arrays, so I wanted to find a way to send it via the serial port.

I wanted to ask if I could get some help writing code for processing and for arduino so that I could send the data of this array from Processing to the array on arduino live over serial. I have never used Processing and I don’t know how to use it, but read that this is a good way to send data to arduino, as well as having a graphical interface for data input.

+4
source share
1 answer

The easiest way I can think of is to send an array with values ​​separated by commas.

GUI

, , , ( ), , .., . , JFrame , - , . . , Java (, ).

, "" Java

, : 16 , , , , 24x16, , , .

Processing/Java Arduino, :

for(int i = 0; i < 16; i++){
  if(i > 0){
    str += ",";//We add a comma before each value, except the first value
  }
  str += frame[i];//We concatenate each number in the string.
  }
  serial.write(str);
}

frame[] - , Arduino.

. ( , ).

import processing.serial.*
void setup(){
    /* Some setup code here */

    /* Opening first port, 9600 baud rate */
    Serial serial = new Serial(this,Serial.list()[0],9600)
}

Arduino

, Arduino, loop() - :

String content = "";
if (Serial.available()) {
  while (Serial.available()) {
    content += Serial.read();
  }
}
long data[16]; //The results will be stored here
for(int i = 0; i < 16; i++){
  int index = content.indexOf(","); //We find the next comma
  data[i] = atol(content.substring(0,index).c_str()); //Extract the number
  content = content.substring(index+1); //Remove the number from the string
}

data[] , .

+4

Source: https://habr.com/ru/post/1530882/


All Articles