Merge pull request #265 from alanbjohnston/pico-v0.39

Pico v0.39
pico
alanbjohnston 3 years ago committed by GitHub
commit 190a25a2a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -82,10 +82,10 @@
#define TRUE 1
#define FALSE 0
#define A 1
#define B 2
#define C 3
#define D 4
#define A_ 1
#define B_ 2
#define C_ 3
#define D_ 4
#define PLUS_X 0
#define PLUS_Y 1
#define BAT 2
@ -108,7 +108,7 @@
#define XS2 15
#define XS3 16
#define RSSI 0
#define RSSI_ 0
#define IHU_TEMP 2
#define SPIN 1
@ -128,14 +128,21 @@
#define PROMPT_TEMP 11
#define PROMPT_FORMAT 12
#define PROMPT_REBOOT 13
#define PROMPT_I2CSCAN 14
#define PROMPT_WIFI 15
#define PROMPT_CAMERA 16
#define PAYLOAD_QUERY 1
#define PAYLOAD_RESET 2
#define PAYLOAD_CLEAR 3
volatile int prompt = false;
volatile int prompting = false;
char serial_string[128];
float get_cpu_temp();
//#define WAV_DATA_LENGTH (50000 * 8)
uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET;
@ -216,6 +223,7 @@ void load_sstv_image_1_as_cam_dot_jpg();
void load_sstv_image_2_as_cam_dot_jpg();
void get_input();
void transmit_led(bool status);
void reset_min_max();
#ifndef STASSID
#define STASSID "Pico"
@ -293,6 +301,8 @@ float lat_file, long_file;
double cpuTemp;
int frameTime;
bool debug_camera = false;
float axis[3], angle[3], volts_max[3], amps_max[3], batt, rotation_speed, period, tempS, temp_max, temp_min, eclipse;
int i2c_bus0 = OFF, i2c_bus1 = OFF, i2c_bus3 = OFF, camera = OFF, sim_mode = FALSE, SafeMode = FALSE, rxAntennaDeployed = 0, txAntennaDeployed = 0;
double eclipse_time;
@ -365,6 +375,8 @@ bool ina219_started = false;
bool camera_detected = false;
bool rotate_flag = true;
int led_builtin_pin;
#define PRESSED 0
#define HELD 0
#define RELEASED 1

File diff suppressed because it is too large Load Diff

@ -175,19 +175,35 @@ void deleteFile(fs::FS &fs, const char * path) {
void setup() {
delay(5000);
// delay(5000);
delay(10000); // was 1000
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT); // Set the pin as output
Serial.println("\nBlink once slowly");
digitalWrite(LED_PIN, LOW); // Turn on
delay (500); // Wait 0.1 sec
digitalWrite(LED_PIN, HIGH); // Turn off
delay(500); // Wait 0.1 sec
// digitalWrite(LED_PIN, LOW); // Turn on
// delay (250); // Wait 0.1 sec
// digitalWrite(LED_PIN, HIGH); // Turn off
// delay(250); // Wait 0.1 sec
// digitalWrite(LED_PIN, LOW); // Turn on
// delay (100); // Wait 0.1 sec
// digitalWrite(LED_PIN, HIGH); // Turn off
// #define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
// #define TIME_TO_SLEEP 10 /* Time ESP32 will go to sleep (in seconds) */
// esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); // testing sleep
Serial.begin(115200);
initialize_camera();
config_camera();
Serial.println("ESP32-CAM Camera initialized v0.2");
Serial.println("ESP32-CAM Camera initialized v0.3");
pinMode(LED_PIN, OUTPUT); // Set the pin as output
@ -208,6 +224,8 @@ void setup() {
}
void loop() {
Serial.println("ESP32-CAM Send JPG over Serial v0.3");
char filename[] = "/cam.jpg";
@ -330,10 +348,10 @@ void config_camera() {
sensor_t * s = esp_camera_sensor_get();
// s->set_brightness(s, 2); // -2 to 2
// s->set_contrast(s, 0); // -2 to 2
// s->set_saturation(s, 1); // -2 to 2
s->set_hmirror(s, 1); // 0 = disable , 1 = enable
s->set_brightness(s, 2); // -2 to 2
s->set_contrast(s, 0); // -2 to 2
s->set_saturation(s, 1); // -2 to 2
s->set_hmirror(s, 0); // 0 = disable , 1 = enable
// s->set_vflip(s, 1);
}
@ -368,6 +386,14 @@ void save_camera_image(char* filename)
Serial.println("- failed to open file for writing");
return;
}
Serial.printf("\nImage length: %d \n", pic->len);
if (pic->len == 15360) {
Serial.println("Invalid JPEG - restarting!");
delay(1000);
esp_restart();
}
for (int k = 0; k < pic->len; k++) {
file.write(pic->buf[k]);

@ -21,7 +21,8 @@ int start_flag_complete = false;
int end_flag_detected = false;
int jpeg_start = 0;
FastCRC8 CRC8;
#define CAMERA_TIMEOUT 12000 // Camera timeout in milli seconds
#define CAMERA_TIMEOUT 10000 // 20000 // Camera timeout in milli seconds
#define ESP32_CAM_ENABLE_PIN 15
//#define GET_IMAGE_DEBUG
@ -30,7 +31,7 @@ FastCRC8 CRC8;
//#define PICOW true
int led_pin = LED_BUILTIN;
bool get_camera_image();
bool get_camera_image(bool debug_camera);
bool start_camera();
bool start_camera() {
@ -66,14 +67,14 @@ bool start_camera() {
delay(100);
Serial2.begin(115200);
#ifdef GET_IMAGE_DEBUG
Serial.println("Started Serial2 to camera v0.1");
Serial.println("Started Serial2 to camera v0.2");
#endif
LittleFS.begin();
bool camera_present = false;
// int tries = 0;
// while ((tries++ < 5) && !camera_present) {
if (get_camera_image()) {
if (get_camera_image(false)) {
camera_present = true;
Serial.println("Camera detected!");
}
@ -165,7 +166,7 @@ void loop() {
}
*/
bool get_camera_image() {
bool get_camera_image(bool debug_camera) {
index1 = 0;
flag_count = 0;
@ -174,16 +175,23 @@ bool get_camera_image() {
end_flag_detected = false;
jpeg_start = 0;
#ifdef GET_IMAGE_DEBUG
Serial.println("Starting get_image_file");
#endif
finished = false;
Serial.println("Enabling ESP32-CAM");
pinMode(ESP32_CAM_ENABLE_PIN, OUTPUT);
digitalWrite(ESP32_CAM_ENABLE_PIN, HIGH);
// #ifdef GET_IMAGE_DEBUG
if (debug_camera)
Serial.println("Received from ESP32-CAM (hex encoded part is JPG image):\n");
// #endif
finished = false;
unsigned long time_start = millis();
while ((!finished) && ((millis() - time_start) < CAMERA_TIMEOUT)) {
if (Serial2.available()) { // If anything comes in Serial2
byte octet = Serial2.read();
byte octet = Serial2.read();
if ((!start_flag_detected) && (debug_camera))
Serial.write(octet);
if (start_flag_complete) {
// Serial.println("Start flag complete detected");
@ -191,7 +199,8 @@ bool get_camera_image() {
if (octet == end_flag[flag_count]) { // looking for end flag
// if (end_flag_detected) {
flag_count++;
#ifdef GET_IMAGE_DEBUG
#ifdef GET_IMAGE_DEBUG
// if (debug_camera)
Serial.println("Found part of end flag!");
#endif
if (flag_count >= strlen(end_flag)) { // complete image
@ -206,7 +215,7 @@ bool get_camera_image() {
int received_crc = Serial2.read();
// buffer2[index1++] = octet;
Serial.print("File length: ");
Serial.print("\nFile length: ");
Serial.println(index1 - (int)strlen(end_flag));
// index1 -= 1; // 40;
// Serial.println(buffer2[index1 - 1], HEX);
@ -215,12 +224,15 @@ bool get_camera_image() {
uint8_t * data = (uint8_t *) &buffer2[0];
#ifdef GET_IMAGE_DEBUG
Serial.println("\nCRC cacluation data:");
Serial.println(buffer2[0], HEX);
Serial.println(buffer2[0], HEX);
Serial.println(buffer2[index1 - 1], HEX);
Serial.println(index1);
Serial.println(received_crc, HEX);
#endif
Serial.println(index1);
#endif
if (debug_camera) {
Serial.print("\nCRC received:");
Serial.println(received_crc, HEX);
}
int calculated_crc = CRC8.smbus(data, index1);
// Serial.println(calculated_crc, HEX);
if (received_crc == calculated_crc)
@ -242,7 +254,8 @@ bool get_camera_image() {
}
/// buffer2[index1++] = octet;
#ifdef GET_IMAGE_DEBUG
//#ifdef GET_IMAGE_DEBUG
if (debug_camera) {
char hexValue[5];
if (octet != 0x66) {
sprintf(hexValue, "%02X", octet);
@ -252,7 +265,8 @@ bool get_camera_image() {
Serial.print("66");
}
// Serial.write(octet);
#endif
}
//#endif
if (index1 > 100000)
index1 = 0;
// }
@ -271,6 +285,10 @@ bool get_camera_image() {
// Serial.println("Resetting. Not start flag.");
}
}
// Serial.println("writing to Serial2");
}
if (debug_camera)
Serial.print("\nCamera complete\n");
digitalWrite(ESP32_CAM_ENABLE_PIN, LOW);
return(finished);
}

@ -30,6 +30,8 @@ The "sketch" will open and you should see a view like this.
Next, you need to install the Raspberry Pi Pico Arduino core, called 'Arduino-Pico'. From their documentation: "Arduino-Pico is a community port of the RP2040 (Raspberry Pi Pico processor) to the Arduino ecosystem, intended to make it easier and more fun to use and program the Raspberry Pi Pico / RP2040 based boards."
IMPORTANT NOTE: You must select the version of Arduino-Pico of 2.3.2. If you use the latest version, SSTV mode will not work.
Here is the documentation for Arduino-Pico: https://arduino-pico.readthedocs.io/en/latest/
Follow the installation instructions listed here: https://arduino-pico.readthedocs.io/en/latest/install.html

Loading…
Cancel
Save

Powered by TurnKey Linux.