Enter Your Project for a chance to win an Oscilloscope Grand Prize Package for the Most Creative Vision Thing Project! | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
All the parts I needed for the LDR camera have now arrived, well almost - the correct Dupont connectors have not yet arrived but I think I might just about have enough existing ones to be able to connect everything together. As my 3D printer is still not working (I haven't tried to get it working so this is not a surprise) I went old-school and used a piece of wood. I had some hardwood plywood left over from making arm rests for chairs which seemed about the right size and thickness so I used that. I used a piece of stripboard (Veroboard) to obtain the correct grid and spacing for the holes, drilling every 0.3 inch. This does space out the LDRs more than I wanted but two hole spacing is only 2 x 2.54 = 5.08 mm so with a 5 mm drill for the LDR itself, this would mean the thickness between adjacent holes would only be 0.08 mm, which didn't seem viable. Still it looks OK with 0.3 inch spacing. I started with a pilot hole of 1.5 mm, then used a bradawl to increase the size of the neck of the hole and then drilled with a 5 mm drill mounted in a pillar drill (Hooray for pillar drills). I allowed the wood to self-centre to the drill when I first started to drill each hole. This could be a bit unsafe if the drill was to catch in the surface of the wood - but I was careful and it didn't. The grid array of holes is not perfect but for manual drilling it is not bad.
As the drill was sharp the holes drilled were 5.0 mm diameter so the LDRs, also 5.0 mm diameter) are a tightish interference fit. It takes a bit of effort to push them in but not enough to damage the LDRs (well - so far anyway) and this means I do not have to glue the LDRs in, making replacement a possibility. Each LDR has to be in series with a 10 kOhm resistor and I decided to use a bit of strip board to hold these resistors (64 in total) and to hold connectors for the Dupont wires. With this number of LDRs and wires I thought it wise to create a rigid structure to hold everything, as well as using connectors rather than soldering, in case I make a mistake.
The connection from each LDR is then connected to one input on the gang of four 16-to-1 analogue multiplexers, as described in a previous Blog. Each of the analogue output signals from the multiplexers is connected to an analogue input on the Arduino Nano, and four channel selection lines (plus an enable signal) come from the Nano to the multiplexer. It is not an especially complex circuit, it is just that there are (or will be) an awful lot of individual wires and connections. A PCB would have been a good idea and one day I'll learn how to use Eagle.
I pretty much used the existing programme for the 1x8 LDR version of the camera, but just set the channel before each analogue measurement is made, using a simple function. I wasn't sure what sort of delay might be needed after changing channels so I put in 20 milliseconds. Once everything is working properly I might look at this on my oscilloscope to see what a better value might be.
void setchannel(int chan)
{
digitalWrite(S0, chan & 0x01);
digitalWrite(S1, chan & 0x02);
digitalWrite(S2, chan & 0x04);
digitalWrite(S3, chan & 0x08);
delay(20); //delay to allow analogue voltage tostabilise
} /* setchannel */
There still isn't anything clever or even compact about the existing programme as I just wanted to check everything was working, before sitting down to think about making a more flexible programme. I will have to do this once the complete 64 LDRs is inserted, maybe.
while (1)
{
setchannel(0);
digitalWrite(enable, LOW); // Enable the analogue mux
matrix.clear(); // clear display
LDRvalue = analogRead(LDR0pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 0, 1);
else
matrix.drawPixel(0, 0, 0);
setchannel(1);
LDRvalue = analogRead(LDR0pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 1, 1);
else
matrix.drawPixel(0, 1, 0);
setchannel(2);
LDRvalue = analogRead(LDR0pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 2, 1);
else
matrix.drawPixel(0, 2, 0);
setchannel(3);
LDRvalue = analogRead(LDR0pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 3, 1);
else
matrix.drawPixel(0, 3, 0);
setchannel(4);
LDRvalue = analogRead(LDR0pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 4, 1);
else
matrix.drawPixel(0, 4, 0);
setchannel(5);
LDRvalue = analogRead(LDR0pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 5, 1);
else
matrix.drawPixel(0, 5, 0);
setchannel(6);
LDRvalue = analogRead(LDR0pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 6, 1);
else
matrix.drawPixel(0, 6, 0);
setchannel(7);
LDRvalue = analogRead(LDR0pin);
Serial.println(LDRvalue);
if (LDRvalue > threshold)
matrix.drawPixel(0, 7, 1);
else
matrix.drawPixel(0, 7, 0);
matrix.writeDisplay(); // write the changes we just made to the display
delay(500);
} /* while */
The video below shows the entire working 1x8 LDR camera, reaady to be expanded to the full 64 LDR camera. Then it will be time for the ANN part.
Dubbie
Top Comments