DIY Photo Sensor

by drtonis in Circuits > Cameras

1932 Views, 6 Favorites, 0 Comments

DIY Photo Sensor

IMG_9010.jpg

Just before eastern I learned that one could use a RAM chip as a photosensor. That sounded very interesting and I looked a little deeper into this topic. Obviously, it is not as simple as it sounds. 

Here are some useful links for this topic:


The biggest challenge is to find a suitable chip. I think I found some that I could order, however they were realtively expensive. Moreover one needs +5V, +12V and -12V to control those chips. 

My initial euphory to build my own photo sensor was gone, however I saw another way:

https://www.instructables.com/DIY-Image-Sensor-and-Digital-Camera/ 

In one of the comments was a recommendation to use a single row of sensors and move them. That sounded exactly what I wanted. No need to invest a fortune for the light sensors and I still could have more pixels as the one shown in the Instructables.

The following is more of a journey description. It is intended to show how I tried to build a photosensor. If you would like to make your own sensor you can use my description, however I don't provide a ready solutions.

PCB Concept and Design

In the mentioned Instructables the guy used 32x32 sensors in a square form (1024 pixels in total). I didn’t want to pay so much for an experimental PCB and so I placed all my light sensor chips in a row. This row one can move and so I could make a sensor with much higher pixel count as this guy did.

After some thinking and planning I settled with 64 pixels in the y-axes. This is already quite a lot since it is 72 mm high. Maybe I could have placed the chips closer to each other, however due to soldering considerations one needs some space between the components. Otherwise, the used 0603 footprint could be smaller, but the PCB supplier didn’t have smaller ones and the one I used were the cheapest ones.

For pin multiplexing I used a simple and cheap CD74HC4067 chip. That allows making from 1 pin 16 pins. Both inputs and outputs are possible. One 4067 is for the voltage reading and the second one is for the power. With two 4067 chips I could theoretically read 256 pixels. Therefore, I use the power 4067 chip only partially.

How to move the pixel PCB? After some consideration I decided to use a 28BYJ-48 stepper motor. It is very cheap and I can use the available 5V. On top of that, I already had several laying around. Unfortunately, the same motor is very imprecise. To overcome this issue I had an idea to use a rotation tracking with AS5600 magnetic encoder.

Additionally, I had an Adafruit ItsyBitsy M4 board laying around and it has enough pins for all the necessary I/O-s. Moreover, it can use Arduino IDE or CircuitPython and it is very fast. I planned to use the whole sensor SW similarly to a 3d printer where a PC is sending commands to the sensor board sends the readings back.

I thought about using an RGB lightsource to try later a color image, therefore a possibility to connect Neopixels was needed.

After some additional components I designed the PCB and after a few weeks they arrived. I ordered partially assembled PCBs. I just had to add 

  • ItsyBitsy
  • Stepper Motor headers
  • Neopixel
  • AS5600 sensor
  • Endstop

First Results

Now I was in the stage where one could start testing. I decided to use the Arduino IDE, since AS5600 has only an Arduino library.

Here are the performed SW tests in more or less chronological order:

  • ItsyBitsy Dot Pixel – worked
  • Neopixel matrix – worked
  • Endstop – worked
  • Stepper Motor – worked
  • AS5600 sensor – worked
  • Light sensor reading – worked
  • Putting everything together – the MCU crashed


I was trying to figure out why it didn’t work, however I wasn’t able to find the reason. The board just crashed and I had to manually install a new bootloader to get it running again. I was annoyed and left the whole thing for some break.

After a few weeks I decided to try again. Still nothing new with the Arduino IDE and I decided to try the CircuitPython. Again the chronological SW building:

  • ItsyBitsy Dot Pixel – I was not able to control the Pixel color, however I was able to turn it off and that was enough
  • Neopixel matrix – worked
  • Endstop – worked
  • Stepper Motor – worked
  • AS5600 sensor – no available library and I tried to use some samples to make my own. My reading was wrong and I thought that my code didn’t work. Later I learned that the sensor was actually broken. I decided to leave the encoder.
  • Light sensor reading – worked
  • Putting everything together – worked
  • Adding Serial reading – worked over Mu Editor
  • Control the sensor board with PC (python) – I wasn’t able to get the connection


During the trial to get the connection between PC and ItsyBitsy I noticed that I wasn’t really able to get a stable connection even with the recommended Mu Editor. I'm quite sure the problem was on my programming skils and somewhere something very simple was missing. Again I was annoyed and frustrated. So far and still it didn't work.

Modifications

2022-10-29 09.42.41.jpg

Since the ItsyBitsy board was not really doing what I wanted I decided to return to the good old Arduino. However, I had a LGT8F328P (Chinese Nano clone) laying around and was again feeling ready for experiments. Unfortunately, the pins don't match. I was able to use most of the Nano pins and for the few not matching ones I had to use some wires to make the connections

After replacing the MCU I started to redo the SW tests and noticed that the AS5600 sent the wrong values. These values looked very similar to the ones that I read with CircuitPything. Most probably I burned the AS5600 somehow and that’s why it didn’t work. I went with the simplest solution and just left the encoder out.

I wasn't able to get the Neopixel library running with the LGT8F328P board. The FastLED library worked and that was sufficient.

LGT8F328P is a 32MHz board. In the stepper motor code I use delays and it took me some time to figure out that it’s 2 times faster than the Arduino Nano. At first the motor didn’t work and I was very annoyed. After increasing the delay 2 times it worked again and I was happy. 28BYJ-48 needs at least a 2ms delay between steps, otherwise it doesn't work.

I tried the serial communication and soon figured out that it would be easier to do with a Raspberry Pi and use the sensor board only for the sensor. At first I planned to add everything on the PCB and the wiring was getting complicated. Now afterwards, I can't explain why I didn't planned it directly from the beginning so. In the end the sensor PCB was used only for light sensing and everything else was handled by Raspberry Pi.

Housing

2022-10-15 09.55.44.jpg
IMG_8998.jpg

Parallel to the SW I thought about housing. I made several iterations till I had the one that worked. I used a 3D printer for everything. The moving axes I solved very simply by just adding one M3 threaded rod and a nut. Despite the play of the M3 nut and screw being large, I was able to limit it with the sliding rails. The sliding rails are quite narrow and so the play is somewhat limited. 

My picture taking procedure look something like that:

  • homing
  • move to the start position
  • read the pixels
  • move 1 pixel distance
  • read the pixels
  • move 1 pixel distance
  • convert the pixel matrix to an image
  • homing


Since the movement is always the same direction I hoped that the inaccurate screw doesn't wiggle too much. Anyway the distance between the pixels is 1.142mm and a slight wiggle wouldn't affect the image quality.

I was thinking about what kind of lens I should use. First I disassembled one old Canon lens and thought about using a lens element from there. I played around a little bit and wasn't happy with the results. The needed distance was much larger than thought between the lens and the focus plane. I decided to use an old camera lens directly.

I ended up with a Canon 35-70mm FD lens with a flange focal distance of 42mm. https://en.wikipedia.org/wiki/Flange_focal_distance

So I decided to place the lens approximately 42mm from the light sensors.

Results

2022-10-24_17-50-40.jpg
2022-10-23_15-09-48.jpg

After several testing I figured out that I could make a 64 x 65 pixel image. I tried several times and the main issue was the sensor reading. I read very dark values. The used lens has several lenses stacked together and each has some light loss. Maybe I should have used a much stronger backlight. Since I already had difficulties getting a reading I skipped the RGB color idea.

The Canon FD lens is intended for the 35mm film and I tried to use it for a 70 x 70 mm area, thus the edges are very dark. Thus, my image corners are not usable. Moreover, the lenst is not placed exactly in the middle of the sensor moving area.

The used stepper motor is slow. I knew about it, but didn't think it through. In the end it was too late to change it. Due to the slow motor it takes 730 sec to take the image (homing + pixel reading) and around 600 seconds to home again. In the end it took more than 20 minutes just for one picture. Not really practical and if I would want to make a color image The time would be 3-4 times higher.

On the two sample images I tried to make a picture from one or two cans. Since I know what I should see on the image I can recognize it. However it has no details and one could assume there are cylindrical objects. The lines are most probably due to the light sensors and moving the sensor.

Conclusion

First I was trying to use ItsyBitsy M4 with Arduino, however I was not able to get the SW running stable. I switched to CircuitPython and again had difficulties with the SW. The challenge was the communication between the sensor module and the control PC. After switching to the Arduino board I was able to control everything as planned. I changed the HW a little bit and simplified the build.

Finding a suitable lens was not as easy as hoped since I didn't want to order something just to scrap it or damage it. After some thinking I settled with an old Canon FD lens. The lens is not intended to be used with such a large photosensor and the image corners are very dark. Additionally I think the lens causes some unwanted light loss.

The image making process takes more than 20 minutes and that is too much for fast adjustments. In order to improve the image quality I need to use another lens. Since the project took so long I decided to end it. I was able to make an image and I learned a lot - so the basic project objectives were fulfilled.