Upcoming maintenance
Dear Customers and Partners.
This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.
This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.
We apologize for any inconvenience.
Camera over serial
-
I'm not really sure what's going on. I have the camera sending the data to a windows PC over serial I have a program in processing that reads the serial data and shows the image. That works flawlessly. I'm trying to get the data to send over an HC-05 bluetooth to the same processing program and it looks like I've got corrupted data.
-
Hi @landon
It looks like the problem is with the Bluetooth connection. Maybe try to test it with less data sent and check if the received data is the same as sent.
Best Regards,
Kamil Tomaszewski -
Hey @landon can you share how are you sending image data to capture image on PC?
-
spresense code
#include <Camera.h> //#define BAUDRATE 1152000 void CamCB(CamImage img){ if(img.isAvailable() == false) return; while (Serial2.available() <= 0); //start by receving 's' if(Serial2.read() != 'S') return; delay(1); digitalWrite(LED0, HIGH); img.convertPixFormat(CAM_IMAGE_PIX_FMT_RGB565); char *buf = img.getImgBuff(); for (int i = 0; i < img.getImgSize(); ++i, ++buf){ Serial2.write(*buf); } digitalWrite(LED0, LOW); } void setup() { Serial2.begin(1152000); while (!Serial2) {}; theCamera.begin(); theCamera.startStreaming(true, CamCB); theCamera.setAutoWhiteBalanceMode(CAM_WHITE_BALANCE_DAYLIGHT); } void loop(){ /* do nothing */ }
Processing side
import processing.serial.*; import java.io.*; Serial myPort; PImage img; final static int WIDTH = 320; final static int HEIGHT = 240; boolean started = false; int serialTimer = 0; int total = 0; int x = 0; int y = 0; void setup(){ size(320, 240); background(0); img = createImage(WIDTH, HEIGHT, RGB); myPort = new Serial(this, "COM7", 115200); myPort.clear(); println("setup Finished"); delay(2000); } void draw(){ if (started == false){ started = true; println("Start"); myPort.write('S'); myPort.clear(); total = 0; delay(10); return; } // To get a stable connection adjust this inerval final int interval = 1; if(millis() - serialTimer > interval){ serialTimer = millis(); if(myPort.available() <=0) return; while (myPort.available() >0) { char lbyte = (char)myPort.read(); char ubyte = (char)myPort.read(); x = total % WIDTH; y = total / WIDTH; int value = (ubyte << 8) | (lbyte); char r = (char)(((value & 0xf800) >> 11) << 3); char g = (char)(((value & 0x07E0) >> 5) << 2); char b = (char)((value & 0x001f) << 3); color c = color(r, g, b); img.set(x, y, c); ++total; if (total >= WIDTH*HEIGHT){ println("end"); myPort.clear(); started = false; total = 0; image(img, 0, 0); break; } } } }
I have tested the bluetooth with a button and turning on and off one of the built in leds and that seems to work. I have posted the code from both programs. Other than changing the serial port on the board this code was some that I have found online.