From 4223aa49731908371e769f1647059b3594de7432 Mon Sep 17 00:00:00 2001 From: James Devine Date: Tue, 6 Aug 2019 19:55:58 +0200 Subject: [PATCH] fixed some bugs before shipping You need to connect the raspberry pi over a cable! Otherwise the EMC breaks events. --- cosmicpi-arduino_V1.6.ino | 67 ++++++++++++++++++++++++++++++--------- gps_reading.ino | 4 +-- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/cosmicpi-arduino_V1.6.ino b/cosmicpi-arduino_V1.6.ino index 4b49d7c..d4fb24a 100644 --- a/cosmicpi-arduino_V1.6.ino +++ b/cosmicpi-arduino_V1.6.ino @@ -200,6 +200,24 @@ void setup() { Serial.begin(SERIAL_BAUD_RATE); Serial.print("ON"); + //init pins that aren't used for stability + pinMode(PA0, INPUT); + pinMode(PA1, INPUT); + pinMode(PA6, OUTPUT); + pinMode(PA7, INPUT); + pinMode(PA8, INPUT); + pinMode(PB0, INPUT); + pinMode(PB1, OUTPUT); + pinMode(PB4, INPUT); + + pinMode(PC9, INPUT); + pinMode(PC11, INPUT); + pinMode(PC12, INPUT); + pinMode(PC13, INPUT); + pinMode(PC14, INPUT); + pinMode(PC15, INPUT); + + if (leds_on) { pinMode(EVT_PIN, OUTPUT); // Pin for the cosmic ray event pinMode(PPS_PIN, OUTPUT); // Pin for the PPS (LED pin) @@ -367,30 +385,22 @@ void setup() { attachInterrupt(digitalPinToInterrupt(PA15), GPS_PPS, RISING); attachInterrupt(digitalPinToInterrupt(PB10), Event_Int, RISING); - Serial.println("INFO: Running\n"); - + //Serial.println(); +sprintf(txt, "INFO: Running\n"); + WriteToOutputBuff(txt); } -void loop() { - pipeGPS(); - ReadFromOutputBuff(); - - //turn off the event led after the set time - if (millis() >= (last_event_LED + event_LED_time)){ - if (leds_on) { - digitalWrite(EVT_PIN, LOW); - } - } -} void GPS_PPS() { + //now PPS is coming through, we can switch off the internal timer. + pps_recieved = true; //stop listening for events while we process this interrupt detachInterrupt(digitalPinToInterrupt(PB10)); //now PPS is coming through, we can switch off the internal timer. - pps_recieved = true; + //pps_recieved = true; //set the pps micros value as the micro time now, and buffer the last value; pps_micros_old = pps_micros; @@ -418,7 +428,9 @@ void GPS_PPS() //now print the sensors //Serial.print("Sensor section"); lsm.read(); /* ask it to read in the data */ - + //debug cmd + //sprintf(txt, "readfail;\n"); + //WriteToOutputBuff(txt); /* Get a new sensor event */ sensors_event_t a, m, g, temp; @@ -484,8 +496,30 @@ Serial.println(';'); } + + + +void loop() { + pipeGPS(); + ReadFromOutputBuff(); + + //turn off the event led after the set time + if (millis() >= (last_event_LED + event_LED_time)){ + if (leds_on) { + digitalWrite(EVT_PIN, LOW); + } + } +} + + void Event_Int() { + detachInterrupt(digitalPinToInterrupt(PB10)); + + + //only count if we've got a PPS +if (pps_recieved == true){ + /* WriteToOutputBuff("evtx:"); ltoa(eventCount,numconvbuff,10); WriteToOutputBuff(numconvbuff); @@ -508,6 +542,9 @@ void Event_Int() if (leds_on) { digitalWrite(EVT_PIN, HIGH); } + + attachInterrupt(digitalPinToInterrupt(PB10), Event_Int, RISING); +} } byte setHV(byte _send) // This function is what bitbangs the data diff --git a/gps_reading.ino b/gps_reading.ino index dcd8651..959e4ba 100644 --- a/gps_reading.ino +++ b/gps_reading.ino @@ -37,12 +37,12 @@ void GpsSetup() { #define NORMAL "$PMTK220,1000*1F" // PMTK_SET_NMEA_UPDATE_1HZ // disables updates for the antenna status (only Adafruit ultimate GPS?) #define NOANTENNA "$PGCMD,33,0*6D" // PGCMD_NOAN -delay(500); //added delay to give GPS time to boot. +delay(5000); //added delay to give GPS time to boot. GPS.println(NOANTENNA); GPS.println(GGAZDA); GPS.println(NORMAL); GPS.println(FMWVERS); - delay(1000); //wait a bit longer and repeat just in case it hasn't booted + delay(10000); //wait a bit longer and repeat just in case it hasn't booted GPS.println(NOANTENNA); GPS.println(GGAZDA); GPS.println(NORMAL);