@noel my mission …
i connect a led in to my arduino board.i need to load a grayscale image and convert it into byte array.because i need binary values of each pixel of my whole image.then i need to blink my led which has connected to arduino ,for its all binary values.
eg:1 st pixel value is 120 ,then send its binary value is 01111000.then led blink serialy 0 1 1 1 1 0 0 0 (low high high high high low low low)
after that as an example 2 nd
pixel value 34 ,then send its binary value is 00100010.then led blink again 0 0 1 0 0 0 1 0 (low low high low low low high low) .
i want to blink all the pixel values through my led sequentialy.
please guide me to do this.what is the way to do this.i know you all good in programing ,i need some help from you
For your project to succeed you have to have o good electronic set up as well.
Forget about using a LDR, because it has a speed response of about 50 ms. You would have to slow down your reading speed. And even for a very small image of 100 by 100 mono pixels (and forgetting about handshaking, stop, and parity bits), it would take more then three hours transfer time.
Then, to avoid outside light interference you need a strong source, a laser diode, or use an optical cable.
But for just a test, you may use a mono led or IR led as transmitter and a photo diode as receiver, one centimeter separated, and do the test in a dark ambient.
As for the “binary stream”, you don’t actually have to worry about this. The Serial lib will take care of this for you. Yes, a byte in Arduino has a value of 0 to 255, the values you have in the text file. (Unlike Processing where a byte has the value of -128 to 127). But you can also use a char.
In the test set up you connect a 330 ohm resistor from the digital port 2 to the cathode of the emitter led (shorter leg), and the anode you connect to ground. Then you load following code:
Then on the other Arduino you connect the cathode of the receiver with a 1k ohm resistor to the ground, and also a wire from the same cathode to digital pin 2. The anode of this photo diode you connect with a 220 ohm resistor to the 5V. Then you load the following code.
The receiver arduino you leave connected to the PC, where you open the serial monitor of the Arduino ide, (be sure to choose same baudrate), and also select the right com port.
I hope you already learned how to get the data from the text file on the SD card with the lib I linked above.
Have fun in the dark!
A minimal example in processing to display bits (LSB to MSB) in a byte and change background:
//https://discourse.processing.org/t/convert-image-in-to-blinking-led-on-processing/15022/22
// I had to work with integers in JAVA but only used lower byte (first 8 bits):
//https://docs.oracle.com/javase/specs/jls/se10/html/jls-5.html#jls-5.6.2
//https://docs.oracle.com/javase/specs/jls/se10/html/jls-15.html#jls-15.22.1
int led = 0;
int mask = 1;
int data = 0x55; // 0x55 hex is 85 decimal is 01010101 binary
int result;
int i;
void setup()
{
size(200, 200);
for(int i=0; i<8; i++)
{
result = mask & data;
if (result > 0)
led = 1;
else
led = 0;
//println(mask, result, led);
print(led);
mask = mask << 1;
}
i = 0;
mask = 1;
println();
}
void draw()
{
if (frameCount%60 == 0)
{
result = mask & data;
if (result > 0)
{
led = 1;
background(0);
}
else
{
led = 0;
background(255, 0, 0);
}
print(led);
mask = mask << 1;
i++;
}
if (i>=8)
{
i = 0;
mask = 1;
println();
}
}
hi @noel
can i use your code for image transmission which i explained??
“ … 1 st pixel value is 120 ,then send its binary value is 01111000.then led blink serialy 0 1 1 1 1 0 0 0 (low high high high high low low low)
after that as an example 2 nd
pixel value 34 ,then send its binary value is 00100010.then led blink again 0 0 1 0 0 0 1 0 (low low high low low low high low) .
i want to blink all the pixel values through my led sequentialy. “
hi @glv
can i send my all pixel value s byte value into blinking led ,which i explained latest post ,using your code??
“… 1 st pixel value is 120 ,then send its binary value is 01111000.then led blink serialy 0 1 1 1 1 0 0 0 (low high high high high low low low)
after that as an example 2 nd
pixel value 34 ,then send its binary value is 00100010.then led blink again 0 0 1 0 0 0 1 0 (low low high low low low high low) .
i want to blink all the pixel values through my led sequentialy. “
Yes. Exactly that. In the code I wrote above three values in a loop are send as a binary stream to the other Arduino throughout a light bundle. You can now modify the loop and access the values from the SD card, and send them in a sequence. When all data are send, you complete printing for instance: println(“end”); On the other Arduino you can capture that in an "if " block and remount the image and, (you didn’t specify what you are wanting to do but I suppose) send it to a Led matrix.
Also please tell me if you did the experiment for which I explained the circuit and gave you the code, and if you saw the values appearing over and over in the serial monitor of the Arduino ide.
You can slow things down and use an LED (transmitter) and LDR (receiver) if the hardware is set up correctly and it is coded correctly. I used my Processing display in place of an LED.
This is what I did:
Created an image (16*16 pixels) that contained colors with brightness from 0 to 255.
It is easier to work with a known image for testing and debugging.
Saved as a BMP file so I could easily see data in file with a hex editor. createImage() / Reference / Processing.org
Read the data one byte at a time from array and displayed the bits one bit at a time to console from LSB to MSB and to sketch window (changed the background).
I integrated the example I posted to do this.
Use Arduino to read the screen with an LDR (placed near sketch display) and turn an LED ON and OFF.
Analog read was used initially: analogRead() - Arduino Reference
Other references:
I made us of the Processing examples that are available to you; seek and you shall find.
I am sharing as much code with you as you have shared with us:
// Blank
What progress have you made on this project?
There is more than one way to do this and I found this interesting enough that I chose to explore it.
I learned a lot from this exercise.
@noel
Thanks for helping me again dear my friend…
Are you sure about your code s are transmitting pixel values in to blinking one LED by convert into binary.In your code there are no any image encoding loop or something there.your code that mention there is very simple .please can you explain what is that simple code there.
Yes I am sure. But you could have responded to @glv because he made a very nice approach where you can see the actual blinking. My code is too fast.It’s somehow difficult to simulate a led blinking with serial byte transfer. Because if you consider a byte like IIIIIIII, you would have a eight bits LED ON time, while a 00000000 value a eight bits time OFF
And with a 01010101 byte it would blink four times . So just to take an average you could have 2 blinks per byte.
The minimum baud rate of the arduino is 300bps But a baud rate is different from the bitrade as it determines how often a channel can change it’s state.
Bit rate = baud rate x the number of bit per baud.
Just to have a rough idea I wrote a code to see until what frameRate I still could see the blinking. For me it’s about 50 That means a 25 times per second blinking of the led. Meaning that my code above does the transfer correctly, but you will not be able to see the blinking. The baud rate is still way to high!
Below the code, but has some interference. Maybe someone can come up with something more accurate.
@noel
I tried with the code. As it seems, the receiving part is having some issues as it is not getting out of Serial.read function because it doesn’t have an end to read. Am ai correct? Please reply mee
The first thing you have to verify , is to see if the text “Receiving…”. appears in the serial monitor of the ide. If not, verify in the dialog box on the bottom if the baud rate is set to 9600 Every time you reset the receiver arduino, this message must appear. This has nothing to do with the sending arduino, because it uses another own serial object. When it does write the message, and everything is installed as I described, with a photo diode (not a LDR), the code will receive characters in the loop forming exactly te values that are send by the other Arduino.
0
150
255 over and over
The best way is to solder the wires because older plugs sometimes have a bad contact. Below as you see I made an image for the setup. And the type of leds to use. Do you see the led from the sender blink for a short time every second?. This part has to work first for you to continue. You can also test aproximating the leds, and it must be in a dark ambient to avoid noise. Even the monitor can give interference. When you get this working I can give you details about how to have it work for a larger distance.
Edit: While it is just a test, you can even connect the leds together with black isolating tape to avoid interference
@noel
hi…tell me why the recieving side arduino ide print “ recieving …” only.i used ldr.If i use a photo transister , the ide prints 0,150,255 ???need all the resisters u mention to the set up if i have to print 0,150,255 or anything I input
Reply my dear friend!!! @noel
If it prints “Receiving…”, that means that the Serial object is working, the baud rate is set up correctly, and the arduino/pc driver works. A serial object is from a class that does the individual settings of the bytes transfer for you, behind the scenes.If you want to see how that works you have to build @glv 's example.
The code has two different serial objects. One called Serial, that is the common one, for communication between pc and arduino. The other is from another lib. The imported Software Serial lib , and called mySerial, for communication between the two arduinos. If you see the sender led blinking, it is working there.
For @glv 's example you can use an LDR,because the bit transfer is slower. At higher speed you need a photo diode.
Of course you need. And with the (aproximating ) values. You also need to test the components with the help of a multimeter. If you connect a led reversed for instance, it can be damaged. You need to learn how to test them.
@noel
hi.thank you very much.
Let me know my friend!! If i use your sending and recieving codes without any changes and with your hardware set up you mention ,can i send any image or number of words directly ?? and recieve from the other side as original data…???my dear friend @noel
Yes. But first you have to buy the components (more then one each) and do the setup. When you have it working, the data you obtained from the image with the code somewhere above, and saved on the SD card on first arduino, can be send to the second arduino connected to the computer where you can display the image on the screen.