Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:45 11 Aug 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : A new PicoMite Camera - 2-Megapixel OV2640

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11732
Posted: 05:22pm 24 Jun 2026
Copy link to clipboard 
Print this post

Version 6.03.00RC25 onwards will have support for the OV2640 camera module that is now ubiquitous and a significant update from the OV7670 that has been supported in multiple versions of MMbasic.



The OV2640 support is available on all RP2350 builds except VGA, VGAUSB and HDMIWEB.
For the HDMI and HDMI builds you must be in mode 4 (RGB555) to use the camera. For the PicoMite builds you will need a connected SPI display (with working MISO) and have enough memory free for the firmware to allocate a 153600 byte buffer in main ram (not PSRAM).
The basic resolution used is 320x240 RGB565 - hence the 153600 byte buffer and the firmware supports capture of images at that resolution and an image change algorithm that will detect motion in the camera field.

All good so far BUT the PicoMite OV2640 firmware also supports jpeg capture in resolutions up to 1600x1200. This allows for a trivial program that can monitor the visual fields for movement and then capture the image in much higher resolution.

Here is the manual entry for the new firmware
  Quote  CAMERA OPEN OV2640 PWDNpin, DCLKpin, HSpin,VSpin, RETpin, D0pin
Initialises the OV2640. For HDMI builds the display must be set to mode 4 before executing the command.
The PWDN pin is driven low to power the sensor up.
DCLK is the camera's pixel-clock output.
Enable OPTION SYSTEM I2C and wire SCL and SDA (may be labelled SIOC
and SIOD) with pullups to 3.3V (2K7 recommended). DCLK may be labelled
PCLK, HS may be HREF and VS may be VSYNC on your module.
D0pin is the start of a range of 8 contiguous pins. The OV2640 always uses
320x240 for the colour preview

CAMERA CAPTURE [scale [,x, y]]
Captures the 320x240 RGB565 preview image, exactly as for the OV7670
CAMERA CAPTURE above (scale and x,y position it on an SPI LCD; on the
HDMI versions it is written to the MODE 4 framebuffer). For a higher-quality
full-colour still use CAMERA CAPTURE JPEG.

CAMERA CAPTURE JPEG fname$ [, resolution [,quality]]
Captures a full-colour image using the camera's hardware JPEG engine and
saves it to the file fname$ (.jpg is added if no extension is given).
resolution selects the image size: VGA (640x480, the default), SVGA
(800x600), XGA (1024x768), SXGA (1280x1024) or UXGA (1600x1200 - the
full 2 megapixels).
quality is HIGH, MEDIUM (the default) or LOW, trading file size against
image quality.
During the capture the display framebuffer is used as working memory, so the
screen is disturbed; the next CAMERA CAPTURE restores the preview. The
saved file can be displayed using LOAD JPG.

CAMERA CHANGE image%(), change! [, scale [, x,y]]
Motion detection with the OV2640, working as for the OV7670 CAMERA
CHANGE above but staying in the 320x240 colour preview mode and using
image brightness as the change measure. Size the array DIM
image%(320*240/8-1). A common use is to loop on CAMERA CHANGE and
trigger CAMERA CAPTURE JPEG when change! exceeds a threshold.


There is also a minor enhancement to the LOAD JPG command to allow images to be downscaled to making reviewing easier.
  Quote  
LOAD JPG file$ [, x] [, y] [,mode] [,ximage] [,yimage] [,scale]
Loads a JPG file from ‘fname$’ and writes it to the current output device
(display or framebuffer) starting at ‘x’, ‘y’ (defaults to 0,0).
The optional ‘mode’ parameter specifies if the output is to be dithered.
Bits 0 and 1 specify the output format and bit 2 specifies the type of dithering
to use.
By default mode is set to -1 which indicates no dithering should be applied.
DITHER_FLOYD_STEINBERG_RGB121 0
DITHER_FLOYD_STEINBERG_RGB222 1
DITHER_FLOYD_STEINBERG_RGB332 2
DITHER_ATKINSON_RGB121 4
DITHER_ATKINSON_RGB222 5
DITHER_ATKINSON_RGB332 6
‘ximage’ and ‘yimage’ specify where in the image file to start writing to the
display (defaults to 0,0)
‘scale’ reduces the displayed size of the image by pixel averaging: use 2 for
50% (each output pixel is the average of a 2x2 block of source pixels) or 4 for
25% (a 4x4 block) and 8 for 12.5% (a 8x8 block). The default is 1 which displays the image at full size.
If an extension is not specified “.JPG” will be added to the file name.
Progressive jpg images are not supported.

Taken together, these changes allow a simple motion detection program
Option explicit
Option default none
Dim float ch
Dim imag%(320*240\8-1)
Dim s$
If Instr(MM.DEVICE$,"HDMI") Then Mode 4
Drive "b:"
Camera open ov2640 gp20,gp21,gp22,gp26,gp27,gp0
Do
 Camera change imag%(),ch' initialise the change image
 Do
   Camera change imag%(),ch,1
 Loop Until ch>10
 s$="Movement"
 Inc s$, LEFT$(Date$,2)+Mid$(Date$,4,2)+RIGHT$(Date$,2)
 Inc s$," "+LEFT$(Time$,2)+Mid$(Time$,4,2)+RIGHT$(Time$,2)+".jpg"
 Camera capture jpeg s$,sxga
 Load jpg s$,,,,,4
 Pause 2000
Loop


Here is a sample image taken at 1600x1200 using my HDMIUSB reference board to control the camera




 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 2048
Posted: 10:19pm 24 Jun 2026
Copy link to clipboard 
Print this post

Do you know if these cameras are IR sensitive, Pete?
I only got a definite maybe from AI.
 
al18
Senior Member

Joined: 06/07/2019
Location: United States
Posts: 248
Posted: 01:10am 25 Jun 2026
Copy link to clipboard 
Print this post

Nice. I see Amazon has the camera on sale for $7.99 during Prime days.

On your picture, it looks like the red color of the camera PCB is being displayed as pink. The blue of the JLCPCB box and the green Raspberry Pico 2 looks correct.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11732
Posted: 07:05am 25 Jun 2026
Copy link to clipboard 
Print this post

  Quote  Do you know if these cameras are IR sensitive, Pete?


I think they may have an IR filter but if so it is a crap one (tested with a TV remote). I couldn't get good pictures looking outside but, of course, the weather here is very hot, bright and hazy so not a good test.

  Quote  On your picture, it looks like the red colour of the camera PCB is being displayed as pink.


Agreed, there are a gazillion registers you can change on these things to tune the colour but this could also be affected by the IR issue. I'm waiting on some IR filters  to see if that improves things.
 
Bryan1

Guru

Joined: 22/02/2006
Location: Australia
Posts: 2201
Posted: 07:24am 25 Jun 2026
Copy link to clipboard 
Print this post

So Peter does this new camera work with a 2350-2W webmite and if so now I got the wifi fixed around the farm it would be nice to get that project done so expect plenty off kangaroo pictures to come up.

Regards Bryan
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11732
Posted: 07:54am 25 Jun 2026
Copy link to clipboard 
Print this post

The camera can be used on the 2350-2W webmite assuming you have enough pins free.
Must be fun having kangaroos to see, all I get is the neighbours cats crapping in the vegetable bed
Edited 2026-06-25 17:55 by matherp
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6567
Posted: 08:26am 25 Jun 2026
Copy link to clipboard 
Print this post

  matherp said  
Must be fun having kangaroos to see,


Chasing them out of the vege garden every morning is good exercise.

Even more exciting is getting a Tassy Devil out of the bathroom.
VK7JH
MMedit
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11732
Posted: 08:27am 25 Jun 2026
Copy link to clipboard 
Print this post

Different world
 
v.lenzer

Senior Member

Joined: 04/05/2024
Location: Germany
Posts: 141
Posted: 09:55am 05 Aug 2026
Copy link to clipboard 
Print this post

Hi Peter!
I’ve connected an OV2640 camera to the WeAct board featuring the RP2350B (along with 6MB of PSRAM). I get an image using the commands:
"Camera open ov2640 gp40,gp41,gp42,gp43,gp44,gp30" and
"Camera capture".
So, everything is fine up to that point. Unfortunately, I cannot use the "Camera capture jpeg" command.
Your "Motion Detector" program crashes with the message:
"Camera capture jpeg s$,sxga
Error: I2C failure". Only "Camera" is listed under "List Commands".
Is "Camera capture jpeg" not included in the firmware I flashed onto the RP2350B? Here are my options:

'PicoMite MMBasic RP2350B V6.03.00
'OPTION SYSTEM SPI GP6,GP3,GP4
'OPTION SYSTEM I2C GP38,GP39
'OPTION FLASH SIZE 16777216
'OPTION COLOURCODE ON
'OPTION PICO OFF
'OPTION CPUSPEED (KHz) 200000
'OPTION LCDPANEL ILI9341, LANDSCAPE,GP7,GP2,GP5
'OPTION TOUCH GP14,GP15
'GUI CALIBRATE 0, 137, 268, 897, 666
'OPTION SDCARD GP8
'OPTION PSRAM PIN GP47

Program:
1K ( 0%) Program (43 lines)
299K (100%) Free

Saved Variables:
16K (100%) Free

RAM:
75K ( 1%) 3 Variables
160K ( 2%) General
6256K (97%) Free

And one more question on the subject: I keep seeing an image that is upside down, no matter how I rotate the camera. Is this due to the camera settings?

I would really appreciate any help from you or the others!
Best wishes! Joachim
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11732
Posted: 10:40am 05 Aug 2026
Copy link to clipboard 
Print this post

transitioning between modes capture to jpeg for example chucks hundreds of commands at the i2c port. Based on your description i would be suspicious of the i2c wiring. Do you have enough pullup but not too much. How long are the cables to the camera?
As to the image upside down, that makes no sense, the image has to be relative to the camera orientation. If the camera is on an angle the image is on an angle. There are register commands than can flip the image and mirror it but they can't compensate for angles and AFAIK the camera doesn't auto-compensate
 
v.lenzer

Senior Member

Joined: 04/05/2024
Location: Germany
Posts: 141
Posted: 02:07pm 05 Aug 2026
Copy link to clipboard 
Print this post

Hi Peter!
Thanks a lot for your quick reply!
I designed an adapter board to which I solder the camera module, allowing me to plug it directly into the port connectors. This keeps the cable length to a maximum of 2 cm. However, I didn't have any 2.7k SMD resistors on hand and hoped that 4.7k ones would work too. That is obviously the reason. Okay, I'll try using standard resistors until I can get hold of some 2.7k SMD ones. I'll get back to you with photos regarding the image orientation.
Here are a few photos of my WeAct board and the adapter board.
















Best wishes! Joachim
 
v.lenzer

Senior Member

Joined: 04/05/2024
Location: Germany
Posts: 141
Posted: 02:49pm 05 Aug 2026
Copy link to clipboard 
Print this post

For a quick-and-dirty solution, I soldered two 4.7k resistors in parallel. The pull-up value is now 2.3k ohms. Unfortunately, the same error message appears.

Here the program:

Motion-detector
 'by Peter Mather, the back shed-forum
 
 
 'PicoMite MMBasic RP2350B V6.03.00
 'OPTION SYSTEM SPI GP6,GP3,GP4
 'OPTION SYSTEM I2C GP38,GP39
 'OPTION FLASH SIZE 16777216
 'OPTION COLOURCODE ON
 'OPTION PICO OFF
 'OPTION CPUSPEED (KHz) 200000
 'OPTION LCDPANEL ILI9341, LANDSCAPE,GP7,GP2,GP5
 'OPTION TOUCH GP14,GP15
 'GUI CALIBRATE 0, 137, 268, 897, 666
 'OPTION SDCARD GP8
 'OPTION PSRAM PIN GP47
 
 Option explicit
 Option default none
 
 Dim float ch
 Dim imag%(320*240\8-1)
 Dim s$
 If Instr(MM.DEVICE$,"HDMI") Then Mode 4
 Drive "b:"
 Camera open ov2640 gp40,gp41,gp42,gp43,gp44,gp30
 
 do while inkey$=""
   camera capture
 loop
 
 Do
   Camera change imag%(),ch' initialise the change image
   Do
     Camera change imag%(),ch,1
   Loop Until ch>10
   s$="Movement"
   Inc s$, LEFT$(Date$,2)+Mid$(Date$,4,2)+RIGHT$(Date$,2)
   Inc s$," "+LEFT$(Time$,2)+Mid$(Time$,4,2)+RIGHT$(Time$,2)+".jpg"
   Camera capture jpeg s$,sxga
   Load jpg s$,,,,,4
   Pause 2000
 Loop


do while inkey$=""
camera capture
loop

This is just there to view and check the image in color.

do while inkey$=""
camera capture
loop

This is just there to view and check the image in color.

A JPG file named "Movement ...." is created. However, the file is 0 bytes in size.





Or could it be that I configured the I2C interface incorrectly? I entered `OPTION SYSTEM I2C GP38,GP39`. However, GP38/39 correspond to I2C2. Or does that not matter?
Edited 2026-08-06 01:00 by v.lenzer
Best wishes! Joachim
 
v.lenzer

Senior Member

Joined: 04/05/2024
Location: Germany
Posts: 141
Posted: 09:28pm 06 Aug 2026
Copy link to clipboard 
Print this post

Hi Peter!
The motion detector is working now with these changes. It’s not JPEG quality—just BMP—but it serves its purpose.

 Do
   Camera change imag%(),ch' initialise the change image
   Do
     Camera change imag%(),ch,1
   Loop Until ch>10
   s$="Movement"
   Inc s$, LEFT$(Date$,2)+Mid$(Date$,4,2)+RIGHT$(Date$,2)
   Inc s$," "+LEFT$(Time$,2)+Mid$(Time$,4,2)+RIGHT$(Time$,2)+".bmp"
   Camera capture
   save image s$
   Load bmp s$
   Pause 2000
 Loop

Best wishes! Joachim
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026