Modifications

Sauter à la navigation Sauter à la recherche
3 341 octets ajoutés ,  6 mars 2022 à 17:20
Ligne 2 : Ligne 2 :     
== Introduction ==  
 
== Introduction ==  
{{ambox|text=Before starting this point, we recommand to follow all the sensors testing steps (BMP280 sensor, TMP36 Sensor, RFM69HCW radio and RFM69HCW Testing).  
+
{{ambox|text=Before starting this point, we recommand to follow all the sensors testing steps (BMP280 sensor, TMP36 Sensor, RFM69HCW radio, RFM69HCW Testing and onboard NeoPixel).  
    
It contains all the details about the wiring, install needed libraries and conduct basic testing.}}
 
It contains all the details about the wiring, install needed libraries and conduct basic testing.}}
Ligne 9 : Ligne 9 :  
* Air temperature
 
* Air temperature
 
* Air pressure
 
* Air pressure
and transmissing the information via the RFM69HCW radio module.
+
and transmitting the information via the RFM69HCW radio module.
    
== Wiring ==
 
== Wiring ==
Ligne 71 : Ligne 71 :  
# Going autonomous (removing Serial Connexion waiting) + add the Lipo
 
# Going autonomous (removing Serial Connexion waiting) + add the Lipo
   −
The code proposed here under has been tested up to 22620128 (22.6 millions) iterations without issue, time when we decided to ends the test :-) .
+
The code proposed here under has been tested up to 23197 iterations without issue, time when we decided to ends the test :-) .
   −
== Understand the code ==
+
Once uploaded to your Feather, open the Serial Monitor and set it to 9600 bauds. '''The sketch would wait until you open the Serial Monitor to start transmitting the data'''.
=== LEDs and errors ===
+
 
Being able to understand rapidly what's happening inside your object is essential to fix the issue.
+
You should see the following messages appears on the Serial Monitor.
 +
 
 +
[[Fichier:ENG-CANSAT-MISSION1-CAPTURE-20.png]]
 +
 
 +
Where we could see the transmitted messages with the packetnum packet index, timing and data.
 +
 
 +
The screen also displays the '''ACK''' acknowledgement send back by the receiver.
 +
 
 +
== Structuring the data ==
 +
The radio module only sends buffer of binary data to the receiver. This is a bit rough but efficient.
 +
 
 +
So to transport the data to the receiver, we need to transform the values (float, integer) into their string representation.
 +
 
 +
When having multiple data in their string representation is not enough, they must also been organized.
 +
 
 +
'''The final format must be easy to parse and very compact''' (smaller is the radio message and higher is the chance for him to get to the ground without error).
 +
 
 +
We propose the following format:
 +
<nowiki>:data1|data2|data3|data4;/r/n</nowiki>
 +
 
 +
where:
 +
* ''':''' is the begin of data stream
 +
* ''';''' is the end of data stream
 +
* '''/r/n''' are optional carriage return + line feed characters.<br />This will would make the messages user friendly when the the messages are viewed in a console or terminal.
 +
* '''|''' is the separator between data items.
 +
* '''datax''' are the string representation of the various data. The characters ;:| are forbidden in this area.
 +
 
 +
we would also recommend to use:
 +
* '''packetnum''' as data1. packetnum is a simple variable increment of one unit after each transmission. This would allow the receiver to detect lost message (since it would exist holes in the numbering of received messages).
 +
* '''timing_info''' as data2. This would help to create timing chart or time base data analysis. We suggest to use the Arduino's {{fname|millis()}} function which count the number of milliseconds since the last microcontroler reset.
 +
 
 +
As explained later in the code the {{fname|packet_str}} variable contains the message to be transmitted to the ground. The Arduino's {{fname|String}} class would ease the transformation of data to their string representation.
 +
<syntaxhighlight lang="c">
 +
String packet_str = String( ":"+String(packetnum,DEC)+"|" );
 +
packet_str.concat( String( ms,DEC)+"|" );
 +
packet_str.concat( String( temperature, 2 )+"|" );
 +
packet_str.concat( String( bme_hpa, 2 )+"|" );
 +
packet_str.concat( String( bme_temp, 2 )+";\r\n" );
 +
</syntaxhighlight>
 +
 
 +
== LEDs and Error management ==
 +
Being able to understand rapidly what's happening inside your object is essential to rapidly fix the issue.
    
The best is to figure out what's happening is to use LED, blink status, heartbeat.
 
The best is to figure out what's happening is to use LED, blink status, heartbeat.
Ligne 116 : Ligne 157 :  
|}
 
|}
   −
=== The code explained ===
+
== The code explained ==
Here some explanation about the {fname|mission1-serial-radio-capture.ino}} sketch used in the CanSat.
+
Here some explanation about the {{fname|mission1-serial-radio-capture.ino}} sketch used in the CanSat.
    
This Arduino sketch would:
 
This Arduino sketch would:
Ligne 268 : Ligne 309 :  
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
The {{fname|init_radio_module()}} function is called from the {{fname|setup()}}.
 +
 +
This function does all the stuff to initialize the RFM69HCW modules. Set the transmission power, the frequency and the '''encryption key'''.
    
<syntaxhighlight lang="c">  
 
<syntaxhighlight lang="c">  
Ligne 310 : Ligne 355 :  
   Serial.println(" MHz");
 
   Serial.println(" MHz");
 
}
 
}
 +
</syntaxhighlight>
    +
This function send the header information to the Serial monitor.
 +
 +
Ideally, this function should also send it via the radio.
 +
 +
<syntaxhighlight lang="c">
 
void send_header() {
 
void send_header() {
  // Send header about the data  Serial.println(F("***START***"));
   
   String s1 = String( F("***HEADER***\r\n") );
 
   String s1 = String( F("***HEADER***\r\n") );
 
   Serial.print( s1 );
 
   Serial.print( s1 );
  // use : as begin of data and ; as end of data
   
   String s2 = String( F(":counter|time_ms|temperature|pressure_hpa|temp2;\r\n") );
 
   String s2 = String( F(":counter|time_ms|temperature|pressure_hpa|temp2;\r\n") );
 
   Serial.print(s2);
 
   Serial.print(s2);
Ligne 322 : Ligne 371 :  
    
 
    
 
}
 
}
 +
</syntaxhighlight>
    +
Helper function used to blink a LED. Note that a pause of 3 time the blinking time. This will ease the identification of blink code into other blinking patterns.
 +
 +
<syntaxhighlight lang="c">
 
void Blink(byte PIN, byte DELAY_MS, byte loops) {
 
void Blink(byte PIN, byte DELAY_MS, byte loops) {
 
   for (byte i=0; i<loops; i++)  {
 
   for (byte i=0; i<loops; i++)  {
Ligne 333 : Ligne 386 :  
   delay( 3* DELAY_MS );
 
   delay( 3* DELAY_MS );
 
}
 
}
 +
</syntaxhighlight>
   −
/*
+
This function returns the voltage for the analog Pin.
* getVoltage() - return the voltage of an analog pin
+
 
*/
+
It converts a digital value between 0 & 1024 (from ADC) to voltage between 0 & 3.3 volts.
 +
 
 +
<syntaxhighlight lang="c">
 
float getVoltage(int pin){
 
float getVoltage(int pin){
   // AS the sketch does not call the analogReadResolution()
+
   // each unit equal 3.3 / 1024 = 3.2 millivolts
  //    function to change the analog reading resolution
  −
  // THEN Arduino use the defaut 12 bits resolution!
  −
  // Under 12 bits resolution, the analogRead() returns
  −
  //    a value between 0 & 1024.
  −
  //
  −
  // Convert digital value between 0 & 1024 to
  −
  //    voltage between 0 & 3.3 volts.
  −
  //    (each unit equal 3.3 / 1024 = 3.2 millivolts)
   
   return (analogRead(pin) * .0032);
 
   return (analogRead(pin) * .0032);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Fault tolerant design ==
 +
The goal is to transmit the data to the ground station.<br />The code of the Emitter (this section) and Receiver (next section) are doing the job.
 +
 +
However, what would happens to your data if the antenna did break? All the data are lots!
 +
 +
This is where the "Extra Flash" would be a great help!
 +
 +
As showed earlier, it is also possible to store/save the data into the Flash.
 +
 +
A good approach would be:
 +
# to save the data in the Flash
 +
# then send it over Radio.
 +
 +
In this way, the data stays available inside the CanSat and could be extracted as suited.
    
{{ENG-CANSAT-TRAILER}}
 
{{ENG-CANSAT-TRAILER}}
29 879

modifications

Menu de navigation