Skip to content

Commit

Permalink
changed
Browse files Browse the repository at this point in the history
  • Loading branch information
PrawiraGenestonlia committed Nov 20, 2018
1 parent 1d6830c commit 7255d38
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
49 changes: 25 additions & 24 deletions CnDH_Main_Arduino/CnDH_Main_Arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ void setup() {
enableMuxPort(4);
mlx.begin();
disableMuxPort(4);
enableMuxPort(6);
setupBQ27441();
disableMuxPort(6);
// enableMuxPort(6);
// setupBQ27441();
// disableMuxPort(6);
if (!SD.begin(PIN_SD_CS, SD_CARD_SPEED))
{
Serial.println("SD card begin error");
Expand All @@ -79,9 +79,10 @@ void loop() {

void update_output() {
output_string = "$;";
enableMuxPort(6);
output_string += String(lipo.soc());
disableMuxPort(6);
// enableMuxPort(6);
// output_string += String(lipo.soc());
// disableMuxPort(6);
output_string += "60";
output_string += ";";
enableMuxPort(1);
SpectralSensor.takeMeasurements();
Expand Down Expand Up @@ -159,24 +160,24 @@ void sd_read_lastline() {
myFile.close();
}

void setupBQ27441(void)
{
// Use lipo.begin() to initialize the BQ27441-G1A and confirm that it's
// connected and communicating.
if (!lipo.begin()) // begin() will return true if communication is successful
{
// If communication fails, print an error message and loop forever.
Serial.println("Error: Unable to communicate with BQ27441.");
Serial.println(" Check wiring and try again.");
Serial.println(" (Battery must be plugged into Battery Babysitter!)");
while (1) ;
}
Serial.println("Connected to BQ27441!");

// Uset lipo.setCapacity(BATTERY_CAPACITY) to set the design capacity
// of your battery.
lipo.setCapacity(BATTERY_CAPACITY);
}
//void setupBQ27441(void)
//{
// // Use lipo.begin() to initialize the BQ27441-G1A and confirm that it's
// // connected and communicating.
// if (!lipo.begin()) // begin() will return true if communication is successful
// {
// // If communication fails, print an error message and loop forever.
// Serial.println("Error: Unable to communicate with BQ27441.");
// Serial.println(" Check wiring and try again.");
// Serial.println(" (Battery must be plugged into Battery Babysitter!)");
// while (1) ;
// }
// Serial.println("Connected to BQ27441!");
//
// // Uset lipo.setCapacity(BATTERY_CAPACITY) to set the design capacity
// // of your battery.
// lipo.setCapacity(BATTERY_CAPACITY);
//}

void transmit_to_SAMD(String info) {
enableMuxPort(7);
Expand Down
34 changes: 25 additions & 9 deletions CnDH_Main_SAMD/CnDH_Main_SAMD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ unsigned long previousMillisDeploy = 0;
unsigned long previousMillisBeacon = 0;

// constants won't change:
const long deployment_time = 180000;
const long deployment_time = 30000;
const long beacon_interval = 2000;
const long interval = 60000; // interval at which to blink (milliseconds)
const long interval = 30000; // interval at which to blink (milliseconds)
String output_string = "";
const byte address[6] = "00001";
char buff[ARRSIZE];
Expand All @@ -59,11 +59,12 @@ int state = 1;
int received_state = 1;
bool deployment = true;
bool start_beacon = false;
char acknowledge[]="999";

void setup()
{
pinMode(LED, OUTPUT);
pinMode(5, OUTPUT);
// pinMode(LED, OUTPUT);
// pinMode(5, OUTPUT);
Wire.begin(7);
Wire.onReceive(receiveEvent);
SerialUSB.begin(115200);
Expand All @@ -81,6 +82,7 @@ void setup()
disableMuxPort1(0);
#endif
//Initialize the Radio.

if (rf95.init() == false) {
SerialUSB.println("Radio Init Failed - Freezing");
while (1);
Expand All @@ -106,6 +108,7 @@ void loop()
{
while (deployment == true) {
unsigned long currentMillisDeploy = millis();
// SerialUSB.println(currentMillisDeploy);
if (currentMillisDeploy - previousMillisDeploy >= deployment_time) {
digitalWrite(5, HIGH);
start_beacon = true;
Expand All @@ -116,29 +119,34 @@ void loop()

}

int received_message2;
String received_message2;
if (rf95.available()) {
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);

if (rf95.recv(buf, &len)) {
timeSinceLastPacket = millis(); //Timestamp this packet
received_message2 = atoi((char*)buf);
received_message2 += (char*)buf;
SerialUSB.print("Got message: ");
SerialUSB.print(received_message2);
SerialUSB.print((char*)buf);
SerialUSB.println();
}
}
if (received_message2 == 999) {
char testt[5];
received_message2.toCharArray(testt,5);
SerialUSB.println(testt);
if (testt[0] == '9') {
digitalWrite(5, LOW);
deployment == false;
}

}

unsigned long currentMillis = millis();

if (currentMillis - previousMillisBeacon >= beacon_interval) {
previousMillisBeacon = currentMillis;
ping_beacon();
ping_beacon2();

}

Expand Down Expand Up @@ -245,6 +253,14 @@ void ping_beacon() {
rf95.waitPacketSent();
}

void ping_beacon2() {
SerialUSB.print("Ping: ");
SerialUSB.print("!101");
SerialUSB.println();
uint8_t toSend[64] = "!101";
rf95.send(toSend, sizeof(toSend));
rf95.waitPacketSent();
}
void receiveEvent(int howMany)
{
while (Wire.available()) {
Expand Down
Binary file added GPS-test.mov
Binary file not shown.

0 comments on commit 7255d38

Please sign in to comment.