Connecting a BW 320x320 Pixels Camera Arducam HM01B0 to Parallax Propeller P2 via 4 Lines
Datasheet: https://www.uctronics.com/download/Datasheet/HM01B0-MWA-image-sensor-datasheet.pdf
This is a black and white Camera Module, which has I2C to set/read registers and can be configured to use a single D0 data connection with a 24MHz synchronous clock line. Thus 4 lines is enough to interface with a microcontroller.
It sends 8bit grey scale values for each pixel. Natively it has a resolution of 320x320 pixels (105kBytes). Also it supports onboard averaging to a 160x120 pixel format, giving 19.200 bytes per picture.
I has automatic exposure by default.
Thanks to P2 Smart Pin Mode for Sync Serial and the great help I got ( https://forums.parallax.com/discussion/178022/synchronous-shift-in-with-external-clock-is-there-a-simple-example#latest ) the serial interface turns out to be totally simple, if you use "gated clock" mode to grab single pictures.
In my setup I use a dedicated I2C bus at ports 33+35. Serial picture data is port 37, Serial picture clock is port 39. In addition GND and 3V3 has to be supplied to the camera. Power consumption is low.
The demo code shows the picture with a ASCII character grey scale.
This is my coffee mug.
The HM01B0 camera gives improved experience in comparison to the OV7670. ( https://forums.parallax.com/discussion/175897/thoughts-about-robot-navigation-using-blinking-beacons-and-camera-s#latest ) Documentation in the datasheet is much better and it works better with low light.
For this I used Spin Tools IDE 0.53.0
Cheers Christof

Comments
Neat. You can probably output this image over VGA or to DVI monitors using my P2 video driver if you want to see the actual full range of pixel levels. Here's a modified version of the demo I gave to MXX that now uses a LUMA mode for greyscale. You can probably adapt it very easily to point to a simple 320x240 8bpp framebuffer by filling the "screenbuf" array with your pixel data. Depending on how you process it all and what format it's in originally maybe it won't be able output at 60Hz, but it's probably nice to see it on a monitor anyway.
For this particular demo the driver is setup to output pixel doubled in X & Y axes running VGA 640x480 resolution. If you need other custom resolutions that better suit your sensor you can potentially adjust some of the settings. For example if you wanted to output 320x320 you could select an EGA style resolution with 32 empty scanlines at the bottom instead of 352 and just pixel double in the X axis only. These spare lines could always be used for another region (eg. text or for GUI menus etc).
You can also choose other colours apart from grey by changing this value to other colours defined in the LUMA_ZZZZ constants in p2videodrv.spin2.
video.LUMA_WHITEUPDATE: Added 320x320 version using EGA output format.
Debug window might be able to display it as well…
Thank you, @rogloh ! Your driver might come handy, depending on what I shall do with the picture, now that I have a stable way to grab it.
Yes, what can we do with a BW picture 320x320 with P2? - Ideas welcome!
(((It's a funny thing, there are very cheap ESP32Cams available. (I have two) But you don't see too many real applications. One problem there ist, that only very few port pins are left over. You also cannot really use these cameras to take "real" pictures for human use, because the quality is rather low. For AI detecting things probably computing power and memory is insufficient. So I have seen some experiments, which will work to some degree, but only to some degree.
I have a birdnet pi running for some time now. This is a raspi with a microphone and a database with AI to detect singing birds and switch off, when it hears people. It gives the birds name and also some probability for the correctness of the detection. This value is very often below 0,8. But in this case for me there is no harm done. It is just interesting fun. )))
The program above with SPIN Tools IDE needs 144 milliseconds to grab one picture320x320. This seems to be independent from exposure time.
Picture160x120 takes 114ms, 8.7fps. I assume, that starting and stopping the stream is not so good for speed. Datasheet indicates max 30fps @24MHz.
Angle of view of this camera is said to be 60° but my measurement shows about 45°.
Probably @ManAtWork 's application to detect a broken tool should be possible with the hm01b0 and P2.
I wonder if 4 bit mode would be better for even higher transfer speed & fps. It'd be neat to have a P2 breakout board for such a sensor as they seem to be pretty cheap devices. If its interface is doable with just a gated PCLKO, 4bit Data, and SCL/SDA pins, that's only 7 pins which would fit within an 8 bit module leaving another IO pin spare, which is maybe useful for VSYNC/interrupt purposes.
I'll have to see if I can source one of these sensors somewhere local and try it out for myself sometime.