Changes between Version 2 and Version 3 of SujetTP8-2016


Ignore:
Timestamp:
Apr 1, 2016, 11:48:30 AM (9 years ago)
Author:
franck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SujetTP8-2016

    v2 v3  
    1010L'API de commande du module NRF est la même sur Arduino et sur RaspberryPI et c'est grâce à ça qu'il est possible d'envisager de commencer par 100% Arduino avant de faire intervenir le RaspberryPI.
    1111
     12**Capteur**
    1213{{{#!c
    1314#include <SPI.h>
     
    4142Adafruit_SSD1306 display(OLED_RESET);
    4243RF24 radio(9,10); // radio(CE,CS)
    43 byte addresses_tx[][6] = {"1sens","2Sens"};
    44 byte addresses_rx[][6] = {"1base","2base"};
     44byte addresses_tx[][6] = {"1fwFW","2fwFW"};
     45byte addresses_rx[][6] = {"1fwFW","2fwFW"};
    4546
    4647// Variables globales pour la communication inter-taches
     
    6970   if (!radio.available()) return;
    7071   radio.read( tsc, sizeof(unsigned long) );
    71    *tscFull = 1;   
     72   *tscFull = 1;
    7273}
    7374
     
    9091  printf_begin();
    9192  radio.begin();
    92   radio.setPALevel(RF24_PA_LOW);
    93   radio.openWritingPipe(addresses_tx[0]);
    94   radio.openReadingPipe(1,addresses_rx[0]);
     93  radio.openWritingPipe(addresses_tx[1]);
     94  radio.openReadingPipe(1,addresses_rx[1]);
    9595  radio.printDetails();
    9696}
    9797
    9898void loop() {
    99   Lumi (0,1000000, PIN_LUMI, &lumi, &lumiFull); 
     99  Lumi (0,100000, PIN_LUMI, &lumi, &lumiFull); 
    100100  SensRF (&lumi, &lumiFull);
    101101  RcvTSC (&tsc, &tscFull);
     
    104104}}}
    105105
     106**Base**
    106107{{{#!c
    107108#include <SPI.h>
     
    135136Adafruit_SSD1306 display(OLED_RESET);
    136137RF24 radio(9,10);
    137 byte addresses_tx[][6] = {"1base","2base"};
    138 byte addresses_rx[][6] = {"1Sens","2Sens"};
     138byte addresses_tx[][6] = {"1fwFW","2fwFW"};
     139byte addresses_rx[][6] = {"1fwFW","2fwFW"};
    139140
    140141// Variables globales pour la communication inter-taches
    141 byte lumi, lumiFull;
    142 
    143 void BaseRF (byte *lumi, byte *lumiFull)
     142byte lumi, lumiFull, pipe;
     143
     144void BaseRF (byte *lumi, byte *lumiFull, byte *pipe)
    144145{
    145    if (!radio.available()) return;
     146   if (!radio.available(pipe)) return;
    146147   radio.read( lumi, sizeof(byte) );
     148   Serial.println(*pipe);
    147149   *lumiFull = 1;   
    148150}
     
    158160}
    159161
    160 void Oled1 (byte *mess,  byte *full) {
     162void Oled1 (byte *mess,  byte *full, byte *pipe) {
     163  static byte value[2];
    161164  if (! (*full) ) return;
    162165  *full = 0;
     166  value[(*pipe) % 2] = *mess;
    163167  display.clearDisplay();
    164168  display.setCursor(0,0);
    165   display.print("Lumiere : ");
    166   display.println(*mess);
     169  display.print("Lumiere 1 : ");
     170  display.println(value[0]);
     171  display.print("Lumiere 2 : ");
     172  display.println(value[1]);
    167173  display.display();
    168174}
     
    175181  display.setTextSize(1);
    176182  display.setTextColor(WHITE);
     183  display.display();
    177184
    178185  printf_begin();
    179186  radio.begin();
    180   radio.setPALevel(RF24_PA_LOW);
    181187  radio.openReadingPipe(1,addresses_rx[0]);
    182188  radio.openReadingPipe(2,addresses_rx[1]);
     
    188194  byte timer=0;
    189195  byte instSendTSC=0;
    190   BaseRF(&lumi, &lumiFull); 
    191   Oled1 (&lumi, &lumiFull);
     196  BaseRF(&lumi, &lumiFull, &pipe); 
     197  Oled1 (&lumi, &lumiFull, &pipe);
    192198  SendTSC (instSendTSC++, timer++, 1000000, addresses_tx[0]);
    193199  SendTSC (instSendTSC++, timer++, 500000,  addresses_tx[1]);