element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Ralph Yamamoto's Blog Camera Module for Raspberry Pi Pico
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 18 Sep 2021 10:56 PM Date Created
  • Views 15295 views
  • Likes 6 likes
  • Comments 4 comments
  • arducam pico4ml
  • rpi pico
  • himax hm01b0
  • processing
  • tinyml
  • rp2040
Related
Recommended

Camera Module for Raspberry Pi Pico

ralphjy
ralphjy
18 Sep 2021

I'm currently participating in the Low Power IoT Challenge.  I am trying to find a low power camera that I can use with the PSoC 62S2.  I've tried the OV7670: Arduino Nano 33 BLE Sense with OV7670 Camera .  I've ruled that one out because it requires more pins than I have available for its 8 bit parallel data interface.

 

The HM01B0 is a monochrome 324x324 camera that has a flexible data interface that can be 1-bit, 4-bit, or 8-bits wide.  The module that I'm using from Arducam: arducam-camera-module-for-raspberry-pi-pico uses the 1-bit interface and only uses 8 of the 16 available pins on the PCB (you could change to a 16 pin header to get the additional data width).  The pin connection to the RPi Pico is shown below.  It uses an I2C interface for configuration (actually an SCCB interface - so requires tweaking).  And in this mode requires 4 pins for the data interface - Pixel Clock, Horizontal Sync, Vertical Sync, and Pixel Data.  So, I could possibly use this with the PSoC 62S2 pins that I have available.  Since the data width is only a single bit there's the obvious concern about the frame rate of the interface.  I'm used to using high resolution color cameras with high speed serial interfaces, so it's a mental attitude adjustment to use lower resolution monochrome cameras to save power.  The HM01B0 utilizes 1-2 mW compared to 50-60 mW for the OV7570.  And I consider the OV7670 to be a relatively low power camera.

 

image

 

I decided to try the HM01B0 in the RPi Pico configuration first before I try anything new (I'll save that for the Low Power IoT Challenge - if I decide to try to use it).

 

Here's a picture of my test setup:

image

 

Arducam has created a board package and examples for the Arduino IDE to make it more user friendly.  Of course it wasn't that friendly, I immediately ran into a problem because they reused some of the names that were used by another third party board package by Earle Philhower that I'm using for some of my other RP2040 boards.  I ended up having to uninstall that other package (you have to manually delete the files) to get it to work.  They also currently appear to have a problem with their SPI and LCD libraries, so I removed them for my test.  I should mention that Arducam has another product the Pico4ML which has an RPi Pico plus an LCD screen and camera arducam-pico4ml-tinyml-dev-kit-rp2040-board-w-qvga-camera-lcd-screen-onboard-audio-b0330…  .  This board package is really for that product, but they use it for the camera demo since it has compatible components.

 

There are quite a few examples that come with this board package (I'm not sure how many of them work):

image

 

I using the Camera HM01B0_USB example which sends a camera image preview over the USB-UART to my PC which uses a Processing sketch to display the image.

image

 

Here's the example program that's uploaded to the Pico:

HM01B0_USB.ino

#include <stdio.h>
#include "pico/stdlib.h"
#include "arducampico.h"
uint8_t header[2] = {0x55,0xAA};
uint8_t image[96*96]={0};
struct arducam_config config;


void setup(){
  Serial.begin(115200);
  gpio_init(PIN_LED);
  gpio_set_dir(PIN_LED, GPIO_OUT);
  config.sccb = i2c0;
  config.sccb_mode = I2C_MODE_16_8;
  config.sensor_address = 0x24;
  config.pin_sioc = PIN_CAM_SIOC;
  config.pin_siod = PIN_CAM_SIOD;
  config.pin_resetb = PIN_CAM_RESETB;
  config.pin_xclk = PIN_CAM_XCLK;
  config.pin_vsync = PIN_CAM_VSYNC;
  config.pin_y2_pio_base = PIN_CAM_Y2_PIO_BASE;
  config.pio = pio0;
  config.pio_sm = 0;
  config.dma_channel = 0;
  arducam_init(&config);
}
void loop() 
{
  gpio_put(PIN_LED, !gpio_get(PIN_LED));
  arducam_capture_frame(&config,image);
  Serial.write(header,2);
  delay(5);
  Serial.write(image,96*96);  
}

 

And the Processing sketch:

preview.pde

/*
  This sketch reads a raw Stream of RGB565 pixels
 from the Serial port and displays the frame on
 the window.

 Use with the Examples -> CameraCaptureRawBytes Arduino sketch.

 This example code is in the public domain.
 */


import processing.serial.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;


Serial myPort;


// must match resolution used in the sketch
final int cameraWidth = 96;
final int cameraHeight = 96;
final int cameraBytesPerPixel = 1;
final int bytesPerFrame = cameraWidth * cameraHeight * cameraBytesPerPixel;


PImage myImage;
byte[] frameBuffer = new byte[bytesPerFrame];
byte[] header = new byte[3];
byte[] score = new byte[2];


void setup()
{


  size(320, 320);


  // if you have only ONE serial port active
  //myPort = new Serial(this, Serial.list()[0], 9600);          // if you have only ONE serial port active


  // if you know the serial port name
  myPort = new Serial(this, "COM17", 115200);                    // Windows
  //  myPort = new Serial(this, "/dev/ttyUSB0", 921600);            // Linux
  // myPort = new Serial(this, "/dev/cu.usbmodem14401", 9600);     // Mac


  // wait for full frame of bytes
  myPort.buffer(bytesPerFrame);  
  myImage = createImage(cameraWidth, cameraHeight, GRAY);
  
  fill(255, 0, 0);
}


void draw()
{
  image(myImage, 0, 0, 320, 320);
}
int state = 0;
int read = 0;
int result = 0;
int startbyte;
void serialEvent(Serial myPort) {
  if (read == 0) {
    startbyte = myPort.read();
    if (startbyte == 0x55) {
      state = 1;
    }
    if (startbyte == 0xAA && state == 1) {
      read = 1; 
    }
    if (startbyte == 0xBB && state == 1) {
      result = 1; 
    }
  }
  if (result == 1) {
     myPort.readBytes(score);
     result = 0;
  }
  if (read ==1) {
    // read the saw bytes in
    myPort.readBytes(frameBuffer);
    // access raw bytes via byte buffer
    ByteBuffer bb = ByteBuffer.wrap(frameBuffer);
    bb.order(ByteOrder.BIG_ENDIAN);
    int i = 0;
    while (bb.hasRemaining()) {
      
      // read 16-bit pixel
      short p = bb.getShort();
      int p1 = (p>>8)&0xFF;
      int p2 = p&0xFF;
      // convert RGB565 to RGB 24-bit
      int r = p1;//((p >> 11) & 0x1f) << 3;
      int g = p1;//((p >> 5) & 0x3f) << 2;
      int b = p1;//((p >> 0) & 0x1f) << 3;


      // set pixel color
      myImage .pixels[i++] = color(r, g, b);
      r = p2;//((p >> 11) & 0x1f) << 3;
      g = p2;//((p >> 5) & 0x3f) << 2;
      b = p2;//((p >> 0) & 0x1f) << 3;


      // set pixel color
      myImage .pixels[i++] = color(r, g, b);
    }
    read = 0;
  }
  myImage .updatePixels();
}

 

 

The camera preview is running at pretty low resolution (96x96), so there are a lot of pixel artifacts.  Here's a snapshot taken over the interface:

image

 

And a short video.  Responsiveness isn't bad at this low resolution.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

I did try playing with the capture resolution but didn't quite get the expected results, although at higher resolutions the update rate was awful.  I'll admit to not being very good with using Processing and to make things worse the documentation available for this camera isn't very good.  I'll need to do more internet searching - I have not found the register definitions yet (couldn't figure out how to flip the image - even though the camera has that capability).

 

If I use this camera I'm sure it will require a lot of tweaking, but definitely meets the low power requirement image.

  • Sign in to reply

Top Comments

  • DAB
    DAB over 3 years ago +2
    Good start. DAB
  • genebren
    genebren over 3 years ago +2
    Ralph, Here is a link to a specification that includes register definitions. https://www.uctronics.com/download/Datasheet/HM01B0-MWA-image-sensor-datasheet.pdf Good luck! Gene
  • ralphjy
    ralphjy over 3 years ago in reply to genebren +1
    Thanks Gene, I must not have used the correct search terms... I see the register I want - "Image_Orientation". I'll have to give that a try. Ralph
  • abdulrahman43
    abdulrahman43 over 3 years ago

    hi Ralph, 

    im currently working on this camera. im using the 1-bit interface. till now the captured image looks so distorted. but i managed tp capture the test patterns correctly. so im thinking the distortion must have something to do with the camera settings (the registers). So, can you elaborate the settings you are using a little ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 3 years ago in reply to genebren

    Thanks Gene,  I must not have used the correct search terms...

     

    I see the register I want - "Image_Orientation".  I'll have to give that a try.

     

    Ralph

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 3 years ago

    Ralph,

     

    Here is a link to a specification that includes register definitions.

     

    https://www.uctronics.com/download/Datasheet/HM01B0-MWA-image-sensor-datasheet.pdf

     

    Good luck!

    Gene

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 3 years ago

    Good start.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube