# How to do the same as "uint16\_t read\_data\[8192\];" in Processing?

**URL:** <https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [August 24, 2021, 4:08pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891 "2021-08-24T16:08:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 4:08pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/1 "2021-08-24T16:08:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 24, 2021, 4:46pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/2 "2021-08-24T16:46:19Z")

</div>

Hello,

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

These are C data types:

> **[C data types](https://en.wikipedia.org/wiki/C_data_types)**
>
> In the C programming language, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in form of declarations for memory locations or variables. Data types also determine the types of operations or methods of processing of data elements.
> The C language provides basic arithmetic types, such as integer and real number types, and syntax to build array and compound types. Headers for the C standard library, to be used via inc...

Processing is JAVA under the hood.

Resources are here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts…

`:)`

---

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 6:10pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/3 "2021-08-24T18:10:14Z")

</div>

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.

```auto
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:

```auto
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.

```auto
EEPROM_iL7
2
2
0
127
0
127
1
0
1
0
29
0
22

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 24, 2021, 6:54pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/4 "2021-08-24T18:54:52Z")

</div>

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]؛

```auto
 int read_data[]; 

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

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 24, 2021, 7:04pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/5 "2021-08-24T19:04:26Z")

</div>

> [@jhsa](#):
>
> ```auto
> void read_all_data() {
> for (uint16_t i = 0; i < 8192; i++) {
> read_data[i] = EEPROMReadInt(p_address + (2 * i));
> }
> }
> 
> ```

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

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 24, 2021, 7:13pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/6 "2021-08-24T19:13:35Z")

</div>

Or it could be

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

```

---

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 8:27pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/7 "2021-08-24T20:27:45Z")

</div>

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 ☹ Can I replace it with an int or something?

Thanks.

João

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 24, 2021, 8:54pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/8 "2021-08-24T20:54:57Z")

</div>

> [@jhsa](#):
>
> wow, guys, so much information. Thank you.  
> Another problem is that byte is also

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

---

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 8:58pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/9 "2021-08-24T20:58:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 24, 2021, 9:04pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/10 "2021-08-24T21:04:08Z")

</div>

> [@jhsa](#):
>
> Processing seems to be more complicated than arduino.

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.

---

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 9:09pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/11 "2021-08-24T21:09:57Z")

</div>

@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.

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

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

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 24, 2021, 9:25pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/12 "2021-08-24T21:25:48Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 9:36pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/13 "2021-08-24T21:36:04Z")

</div>

@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. ☹ Well, all is hard when we don’t know how to do it… This is why i am here asking for help.  
Thanks

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 24, 2021, 9:40pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/14 "2021-08-24T21:40:11Z")

</div>

> [@jhsa](#):
>
> Probably because i don’t know what to look for.

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

Search this on YouTube (arduino and processing projects)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 24, 2021, 10:07pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/15 "2021-08-24T22:07:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 10:27pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/16 "2021-08-24T22:27:16Z")

</div>

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…

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 24, 2021, 10:28pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/17 "2021-08-24T22:28:29Z")

</div>

Hello,

I was having some fun with this…

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

> **Code**
>
> ```auto
> //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:

> **[Data](https://processing.org/tutorials/data/)**
>
> Learn the basics of working with data feeds in Processing.

`:)`

---

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 10:49pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/18 "2021-08-24T22:49:22Z")

</div>

@glv, wow. That is some coding… I wish i will ever get to the level of understanding what you did 🙂 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?

---

<div class="post-metadata">

**Author:** ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)\
**Post date:** [August 24, 2021, 11:14pm UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/19 "2021-08-24T23:14:41Z")

</div>

Also got bitRead to work 🙂 Here is the code

```auto
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.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 25, 2021, 12:25am UTC](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891/22 "2021-08-25T00:25:44Z")

</div>

Hello @jhsa ,

I was a bit fiddler in my heyday!

```auto
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.

`:)`

[Next page](https://discourse.processing.org/t/how-to-do-the-same-as-uint16-t-read-data-8192-in-processing/31891.md?page=2)
