Skip to content

Commit 0d11424

Browse files
committed
Fixed SD card example
1 parent 5916d1b commit 0d11424

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

examples/image_transfer_jpg_as_the_controller_device_example/image_transfer_jpg_as_the_controller_device_example.ino

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@ const int SD_CARD_CHIP_SELECT_PIN = 4;
1818
// We need to define a scratch buffer for holding messages. The maximum amount of data
1919
// you may pass in any on direction is limited to the size of this buffer.
2020

21-
openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer.
21+
// PLEASE NOTE THAT THE OPENMV CAM OUTPUTS BURST DATA AT A VERY HIGH RATE BACK TO BACK
22+
// THAT SOME ARDUINOS MAY NOT BE ABLE TO HANDLE. ONLY MAKE THE BUFFER SIZE LARGER FOR
23+
// INTERFACES WHICH CAN HANDLE A HIGH BURST RATE.
24+
25+
openmv::rpc_scratch_buffer<32> scratch_buffer; // All RPC objects share this buffer.
2226

2327
///////////////////////////////////////////////////////////////
2428
// Choose the interface you wish to control an OpenMV Cam over.
2529
///////////////////////////////////////////////////////////////
2630

27-
// Uncomment the below line to setup your Arduino for controlling over CAN.
28-
//
29-
// * message_id - CAN message to use for data transport on the can bus (11-bit).
30-
// * bit_rate - CAN bit rate.
31-
//
32-
// NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave
33-
// can high and master can low to slave can lo. The can bus must be terminated with 120 ohms.
34-
//
35-
// openmv::rpc_can_master interface(0x7FF, 250E3);
31+
// CAN AND SPI INTERFACES CANNOT BE USED BECAUSE THE SD CARD LIBRARY
32+
// USES THE SPI BUS AND DOES NOT SHARE SPI BUS ACCESS NICELY.
3633

3734
// Uncomment the below line to setup your Arduino for controlling over I2C.
3835
//
@@ -44,17 +41,6 @@ openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this bu
4441
//
4542
// openmv::rpc_i2c_master interface(0x12, 100000);
4643

47-
// Uncomment the below line to setup your Arduino for controlling over SPI.
48-
//
49-
// * cs_pin - Slave Select Pin.
50-
// * freq - SPI Bus Clock Frequency.
51-
// * spi_mode - See (https://www.arduino.cc/en/reference/SPI)
52-
//
53-
// NOTE: Master and slave settings much match. Connect CS, SCLK, MOSI, MISO to CS, SCLK, MOSI, MISO.
54-
// Finally, both devices must share a common ground.
55-
//
56-
// openmv::rpc_spi_master interface(10, 1000000, SPI_MODE2);
57-
5844
// Uncomment the below line to setup your Arduino for controlling over a hardware UART.
5945
//
6046
// * baudrate - Serial Baudrate.
@@ -115,31 +101,31 @@ void setup() {
115101

116102
void loop() {
117103
// The script running on the OpenMV Cam will evaluate the string below to set the pixformat and framesize.
118-
const char pixformat_and_framesize[] = "Sensor.RGB565,Sensor.QVGA";
104+
const char pixformat_and_framesize[] = "sensor.RGB565,sensor.QQQVGA";
119105
uint32_t jpeg_size;
120106

121107
// jpeg_image_snapshot will take a jpeg picture, store it in memory on the OpenMV Cam, and then return the
122108
// jpg image size in bytes for reading by the Arduino.
123109
Serial.println(F("Taking a pic..."));
124110
if (interface.call(F("jpeg_image_snapshot"),
125-
pixformat_and_framesize, sizeof(pixformat_and_framesize),
111+
pixformat_and_framesize, sizeof(pixformat_and_framesize) - 1, // Do not send NULL terminator
126112
&jpeg_size, sizeof(jpeg_size))) {
127113
Serial.println(F("Success"));
128114

129115
// We need to generate a filename now to save the jpg image data too. The below code reformats the
130116
// 5-digit file name string based on a counter that will increment each time we save an image.
131117
static uint16_t file_counter = 0;
132118
char filename[] = "00000.JPG";
133-
filename[0] = ((file_counter / 10000) % 10);
134-
filename[1] = ((file_counter / 1000) % 10);
135-
filename[2] = ((file_counter / 100) % 10);
136-
filename[3] = ((file_counter / 10) % 10);
137-
filename[4] = ((file_counter / 1) % 10);
119+
filename[0] += ((file_counter / 10000) % 10);
120+
filename[1] += ((file_counter / 1000) % 10);
121+
filename[2] += ((file_counter / 100) % 10);
122+
filename[3] += ((file_counter / 10) % 10);
123+
filename[4] += ((file_counter / 1) % 10);
138124

139125
// Try to create the filename. If a file already exists with the same name it will be deleted.
140126
Serial.println(F("Creating jpg file..."));
141-
SD.remove(filename);
142-
File jpg_file = SD.open(filename, FILE_WRITE);
127+
Serial.println(filename);
128+
File jpg_file = SD.open(filename, O_WRITE | O_CREAT | O_TRUNC);
143129

144130
if (jpg_file) {
145131
// jpeg_image_read takes two arguments, offset and size.

0 commit comments

Comments
 (0)