How to do the same as "uint16_t read_data[8192];" in Processing?

As the title says,
How to do the same as “uint16_t read_data[8192];” in processing?
Thank you in advance for your answers.

João

Hello,

These are the JAVA data types:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

These are C data types:

Processing is JAVA under the hood.

Resources are here:

:)

Ok, I think I will have to explain better what I want to do.

I am trying to make an eeprom editor for a DIY guitar effect switcher that we develop.
Every eeprom slot uses two bytes combined. Here is the Arduino code.

uint16_t read_data[8192];
uint16_t p_address;

void EEPROMWriteInt(uint16_t p_address, uint16_t p_value)//write values more than 8 bits in eeprom
{
  uint8_t Byte1 = ((p_value >> 0) & 0xFF);
  uint8_t Byte2 = ((p_value >> 8) & 0xFF);
  myEEPROM.write(p_address, Byte1);
  myEEPROM.write(p_address + 1, Byte2);
}
uint16_t EEPROMReadInt(uint16_t p_address)
{
  uint8_t Byte1 = myEEPROM.read(p_address);
  uint8_t Byte2 = myEEPROM.read(p_address + 1);
  uint16_t firstTwoBytes = ((Byte1 << 0) & 0xFF) + ((Byte2 << 8) & 0xFF00);
  return (firstTwoBytes);
}

Every slot then has 16 bits.

Then to read the data from the eeprom we have:

void read_all_data() {
  for (uint16_t i = 0; i < 8192; i++) {
    read_data[i] = EEPROMReadInt(p_address + (2 * i));
  }
}

Then I send the eeprom values over serial to processing and save it to a text file. Every line of this file represents every byte of the eeprom. 8 bits.
Now i need to recombine them again into lines of 16 bits. But how would i do that in processing?
the Eeprom data on the text file is writen as the example below. Every line represents a byte.

EEPROM_iL7
2
2
0
127
0
127
1
0
1
0
29
0
22

As the title says,
How to do the same as “uint16_t read_data[8192];” in processing?
Thank you in advance for your answers.

João

uint16_t read_data[8192]؛

 int read_data[]; 


void setup(){
  size(640,320);
 read_data = new int[8192]; 
}

void read_all_data() {
for (int i = 0; i < 8192; i++) {
read_data[i] = EEPROMReadInt(p_address + (2 * i));
}
}

Or it could be

for (int i = 0; i < read_data.length; i++) {
read_data[i] = EEPROMReadInt(p_address + (2 * i));
}
}

wow, guys, so much information. Thank you.
Another problem is that byte is also different from Arduino. -128 to 127? I find this a bit weird though :frowning: Can I replace it with an int or something?

Thanks.

João

You can replace everything

Later I have on my PC Arduino code I converted it to processing I am going to post it’s run as Arduino run

Thank you. I am really struggling. I am a beginner and I am trying to do stuff that is way beyond my comprehension. Processing seems to be more complicated than arduino. I will also have to find replacements for bitRead and bitWrite. I hope it is possible.

On the contrary processing very close to Arduino and very easy to understand

I will also have to find replacements for bitRead and bitWrite. I hope it is possible.

Give an example for this in Arduino
bitRead and bitWrite. I hope it is possible.

@jafal, thank you so much for your precious help, and I hope this will help others, as I couldn’t find much information out there. Probably because i don’t know what to look for.
This is some of the eeprom code on the arduino.
On the processing code, the text file should be an emulation of the Arduino eeprom.

EEread = read_data[(ActiveBank + PresetNumber) + (ActiveBank * 8) + 20];

Pedal1_Rev = bitRead(EEread, 10);
  Pedal2_Rev = bitRead(EEread, 11);

@jhsa note that if you want processing to deal with outside hardware you must use Arduino and you don’t have to clone Arduino code to processing

Processing then can control your Arduino to do different tasks
You can make processing for instance up down volume of your guitar or any other desirable things you need

You can start reading about processing serial library and Arduino

@jafal, I already made some code to save / restore the eeprom from / to the arduino.
Now i just need to take those values on the txt file I created which has the eeprom values, edit them, and save them back to the file. But this seems to be hard in processing. :frowning: Well, all is hard when we don’t know how to do it… This is why i am here asking for help.
Thanks

You are true 99% for solving any issue is that to know what we need

Search this on YouTube (arduino and processing projects)

@jhsa what Is your aim from processing in your project?

My aim is to make an EEprom editor for our guitar effect switcher. A friend and myself, we have been developing it together since 3 years now using arduino and and STM32F103 board. I am a musician that normally cannot afford expensive equipment, so i try to build my own stuff. And like me there are many other musicians. So, this project is free for everyone to build. Perhaps it will help other guitar players that are able to mess with electronics :).
But now I have decided that the project deserves a nice editor for the PC. It does not have to be a real time editor. As I said, I can now dump its eeprom to the PC using processing, and the format I use is the one shown in the example above. every slot of the eeprom on each line of the text file. The problem is that on the device we use 2 eeprom slots (2 bytes) combined to make a 16 bit slot, hence the code i posted above.
And with your help I think I am reading and combining the two lines correctly already. here is the code. I am testing reading only for now. If I am not able to process the data, it wouldn’t be worth it to continue with the project…

String EepromData[];

int read_data[];
int p_address;

void setup(){
  size(640,320);
 read_data = new int[8192]; 
 selectInput ( "Open iLoopino8 Eeprom:", "fileSelectedOpen", dataFile( "*.il8" ));
 
 
 
}

void draw() {
  
}

void fileSelectedOpen(File selection) {

  if (selection == null) {

  } else {

    EepromData = (loadStrings(selection.getAbsolutePath()));

  read_all_data();
    println(read_data[21]);
  }

}

void read_all_data() {
for (int i = 0; i < 8192; i++) {
read_data[i] = EEPROMReadInt(p_address + (2 * i));
}
}

void EEPROMWriteInt(int p_address, int p_value)//write values more than 8 bits in eeprom
{
  int Byte1 = ((p_value >> 0) & 0xFF);
  int Byte2 = ((p_value >> 8) & 0xFF);

  EepromData[p_address + 1] = str(Byte1);
  EepromData[p_address + 2] = str(Byte2);
}
int EEPROMReadInt(int p_address)
{
  int Byte1 = int(EepromData[p_address + 1]);
  int Byte2 =  int(EepromData[p_address + 2]);
  int firstTwoBytes = ((Byte1 << 0) & 0xFF) + ((Byte2 << 8) & 0xFF00);
  return (firstTwoBytes);
}

Hello,

I was having some fun with this…

It looks like you are well under way to complete this.

Code
//https://processing.org/tutorials/data

String[] sData;  //String
byte[] bData;    //byte
short[] shData;  //short
int[] iData;     //int 
String[] oData;  //String 

void setup() 
  {
  size(200, 200);
  
  // Load text file as a String
  String[] sData = loadStrings("data.iL7");
  printArray(sData);
  println();
  
  bData = new byte[sData.length];
  shData = new short[sData.length/2];
  iData = new int[sData.length/2];
  oData = new String[sData.length/2];
  
  for(int i = 0; i<bData.length; i++)
    {
    bData[i] = byte(int(sData[i]));
    }
  printArray(bData);
  println();

  for(int i = 0; i<shData.length; i+=1)
    {
    shData[i] = (short)(bData[2*i] | bData[2*i+1]<<8);
    }
  printArray(iData);
  println();


  for(int i = 0; i<iData.length; i+=1)
    {
    iData[i] = bData[2*i] | bData[2*i+1]<<8;
    }
  printArray(iData);
  println();  
  
  for(int i = 0; i<bData.length; i+=2)
    {
    println(hex(bData[i+1]), hex(bData[i]), "   ", bData[i+1], bData[i] );
    println(hex(shData[i/2], 4));
    println(hex(iData[i/2], 8));
    }

  for(int i = 0; i<iData.length; i+=1)
    {
    oData[i] = hex( iData[i] ); 
    //oData[i] = str( iData[i] );      
    }
    
   saveStrings("output.txt", oData); 
  }

This will take the file with these values:

Input file

2
2
0
127
0
127
1
0
1
0
29
0
22
15

And convert to:

Output file

00000202
00007F00
00007F00
00000001
00000001
0000001D
00000F16

This is just an example for you and some very “rough” code.

Reference:

:)

@glv, wow. That is some coding… I wish i will ever get to the level of understanding what you did :slight_smile: It does seem to be getting the correct output, even if i don’t need it in HEX. Did you have a look at the code I have just posted above? At least the reading seems to be working correctly. And after editing, it will have to be split in two again and be saved as a string to the correct line of the file. Also, that output will be assigned to variables, and while editing them, I will have to edit single bits.
For example, the effect switcher has 8 outputs that can be turned ON or OFF independently, Each one of those outputs reperesent one bit of the first 8 bits of that 16 bit output. The other 8 bits are also other 0/1 variables. Every 16 bit slot represent one preset of the switcher… Does it make sense?

1 Like

Also got bitRead to work :slight_smile: Here is the code

println(bitRead(read_data[29], 10)); // Use like this
// or
int value = bitRead(read_data[7], 1);

int bitRead(int b, int bitPos)
    {
      int x = b & (1 << bitPos);
      return x == 0 ? 0 : 1;
    }

Need to sort bitWrite, but not really sure how to do it. I found it online by the way. Been doing reading nearly all day.

1 Like

Hello @jhsa ,

I was a bit fiddler in my heyday!

void setup()
  {
  for(int i=0; i<16; i++)
    {
    print(bitRead(0xAA55, i));
    }
  println();
  println(binary(0xAA55, 16));  
    
  println();
  int bTest = 0xFF00;
  println(binary(bTest, 16));
  bTest = bitSet(bTest, 1);
  println(binary(bTest, 16));
  bTest = bitClear(bTest, 14);
  println(binary(bTest, 16));
  }

int bitRead(int b, int bitPos)
      {
      int x = b & (1 << bitPos);
      return x == 0 ? 0 : 1;
      }
      
int bitSet(int b, int bitPos)
      {
      int x = b | (1 << bitPos);
      return x;
      }
      
int bitClear(int b, int bitPos)
      {
      int x = b & ~(1 << bitPos);
      return x;
      }       

It may need some testing and tweaking! A bit late for me to be coding.

:)