|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +!!! attention "Important!" |
| 6 | + This is an advanced example that assumes users are familiar with using the [Pico SDK](https://www.raspberrypi.com/documentation/pico-sdk/) to build and run projects. If you have not previously used the Pico SDK we strongly encourage going through Raspberry Pi's tutorials on getting started with it before continuing with this example. |
| 7 | + |
| 8 | +The Arducam PSRAM Example is a modified version of [Arducam's Videostreaming example](https://github.com/ArduCAM/PICO_SPI_CAM/tree/master/C/Examples/Arducam_MINI_5MP_Plus_Videostreaming) that uses the Arducam to take still images and send them to the RP2350 and then process and transmit the images over USB to be displayed using a [Processing](https://processing.org/) sketch. The primary goal of this example is to demonstrate how to set up and use PSRAM on the Pro Micro - RP2350 using the Pico SDK and the cool images are a neat bonus! |
| 9 | + |
| 10 | +## Software Requirements |
| 11 | + |
| 12 | +Along with the Pico SDK, you'll need to install the following items for this demo to run properly. |
| 13 | + |
| 14 | +### Pico SDK Cam Driver |
| 15 | + |
| 16 | +This example uses the Pico SDK, Arducam's Pico Cam driver for the SDK. The example files include the necessary Arducam driver installation but if you'd like to install it separately you can find it in the ArduCAM GitHub repo [here](https://github.com/ArduCAM/PICO_SPI_CAM). |
| 17 | + |
| 18 | +### Processing Software |
| 19 | + |
| 20 | +You'll also need to download and install the [Processing](https://processing.org/) software. You can download the program by clicking the button below: |
| 21 | + |
| 22 | +<center> |
| 23 | + [Processing Downloads Page](https://processing.org/download){ .md-button .md-button--primary} |
| 24 | +</center> |
| 25 | + |
| 26 | +### Arducam Demo Files |
| 27 | + |
| 28 | +We've included pretty much everything you'll need to run the example in the Pro Micro - RP2350 GitHub repository [here](https://github.com/sparkfun/SparkFun_Pro_Micro_RP2350/tree/main/Examples/Arducam_Demo). If you'd like to download a compressed (ZIP) copy of the repository, click the button below: |
| 29 | + |
| 30 | +<center> |
| 31 | + [SparkFun Pro Micro - RP2350 Github Repository (ZIP)](https://github.com/sparkfun/SparkFun_Pro_Micro_RP2350/archive/refs/heads/main.zip){ .md-button .md-button--primary} |
| 32 | +</center> |
| 33 | + |
| 34 | +The C++, .uf2, and cmake.txt files for the example can be found in the "<b>/Examples/Arducam_Demo</b>" folder. Take note of where these are as we'll need them later on. |
| 35 | + |
| 36 | +## Uploading and Running Demo |
| 37 | + |
| 38 | +With the Pico SDK set up on your computer, use the following command from the example directory to build the project: |
| 39 | + |
| 40 | +``` c++ |
| 41 | +mkdir build |
| 42 | +cd build |
| 43 | +cmake .. -DPICO_PLATFORM=rp2350 -DPICO_BOARD=sparkfun_promicro_rp2350 |
| 44 | +make |
| 45 | +``` |
| 46 | + |
| 47 | +Next, set the Pro Micro in boot mode and upload the .uf2 file to the board. |
| 48 | + |
| 49 | +### Processing Sketch |
| 50 | + |
| 51 | +Now that the Pro Micro - RP2350 is running the demo code, open the Processing sketch included in the GitHub repository download. Finally, click the "Run" button in the top left of the Processing window and it should open a new window to display the images the camera is taking. We've done our best to speed up the time between the Arducam capturing an image and displaying it on the computer but it can take a few seconds in between shots. With the camera steady, you should start to see greyscale images like this fancy photo of the ceiling in the SparkFun engineering department: |
| 52 | + |
| 53 | +<figure markdown> |
| 54 | +[{ width="400"}](./assets/img/arducam_image1.png "Click to enlarge") |
| 55 | +</figure> |
| 56 | + |
| 57 | +Now try unplugging the jumper wire between A3 and GND and the next images should be in purely black and white (thresholded) like the screenshot below: |
| 58 | + |
| 59 | +<figure markdown> |
| 60 | +[{ width="400"}](./assets/img/arducam_image2.png "Click to enlarge") |
| 61 | +</figure> |
| 62 | + |
| 63 | +## PSRAM Code to Note |
| 64 | + |
| 65 | +!!! note "Pico SDK PSRAM Support" |
| 66 | + The Pico SDK may include official PSRAM support for the Pro Micro - RP2350 in the future. This is simply a demo to get users started while that support is being implemented. |
| 67 | + |
| 68 | +The primary goal of this demo is to show how to implement and use PSRAM in your own projects. It's fairly involved and requires overriding the default PSRAM allocations to work with the Pro Micro. |
| 69 | + |
| 70 | +### CMakeLists.txt |
| 71 | + |
| 72 | +The CMakeLists.txt file includes the commands to override the default allocation to use a custom allocation created in the "sfe_pico_alloc" folder. |
| 73 | + |
| 74 | +``` |
| 75 | +# use our own allocator |
| 76 | +set(SKIP_PICO_MALLOC 1) |
| 77 | +``` |
| 78 | + |
| 79 | +It then adds a subdirectory called "sfe_pico_alloc" to import the custom PSRAM memory allocation for the Pro Micro - RP2350. |
| 80 | + |
| 81 | +``` |
| 82 | +add_subdirectory(sfe_pico_alloc) |
| 83 | +
|
| 84 | +# pull in common dependencies and additional spi hardware support |
| 85 | +target_link_libraries(arducam_demo |
| 86 | + pico_stdlib |
| 87 | + hardware_dma |
| 88 | + hardware_i2c |
| 89 | + hardware_pwm |
| 90 | + ArduCAM |
| 91 | + sfe_pico_alloc |
| 92 | +) |
| 93 | +``` |
| 94 | + |
| 95 | +### C++ PSRAM |
| 96 | + |
| 97 | +The code snippet below shows how to configure and use PSRAM with <code>malloc()</code>. |
| 98 | + |
| 99 | +``` c++ |
| 100 | +// Create buffer to store image. In this demo, malloc() has been configure to |
| 101 | +// use the PSRAM of the SparkFun Pro Micro RP2350, so you don't need to do |
| 102 | +// anything else to use the PSRAM! |
| 103 | +imageBuf = (uint8_t*) malloc(nRows * nCols); |
| 104 | +if (!imageBuf) |
| 105 | +{ |
| 106 | + // Always good practice to verify that malloc() worked |
| 107 | + printf("Malloc failed! Exiting example\n"); |
| 108 | + return 1; |
| 109 | +} |
| 110 | +``` |
0 commit comments