Shop OBEX P1 Docs P2 Docs Learn Events
Help with Conversion From Arduino C to Propeller1 Spin — Parallax Forums

Help with Conversion From Arduino C to Propeller1 Spin

Hello, I am making progress with the issue described here.
I found some code to use these things with an Arduino, alongside pin definitions, and pinout diagrams. Can anyone here who uses the Prop1 and has Arduino experience please help me decipher this code?
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);
  
  radio.stopListening();
}

void loop()
{
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  
  delay(1000);
}
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
  while (!Serial);
  Serial.begin(9600);
  
  radio.begin();
  radio.openReadingPipe(0, rxAddr);
  
  radio.startListening();
}

void loop()
{
  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
    
    Serial.println(text);
  }
}
First chunk is transmitter, second chunk is receiver.

Comments

  • I'll try to find the three libraries used in this.
  • kwinnkwinn Posts: 8,697
    My total experience with arduino amounts to replacing a single board with a propeller board a couple of years ago so take the following comments with a grain of salt.
    *******************************************************************************************
    
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    
    These includes would need to be replaced with equivalent objects or code 
    
    RF24 radio(7, 8);   '*********** probably send/receive pins on arduino
    
    *******************************************************************************************
    const byte rxAddr[6] = "00001"; *********** setting data in an array location ??? (purpose unknown at present)
    
    void setup()
    {
      radio.begin();                    ********** startup for the RF24 module
      radio.setRetries(15, 15);         ********** number of retries for send & receive   ???
      radio.openWritingPipe(rxAddr);    ********** set RF24 to transmit data ???
      
      radio.stopListening();            ********** Turn receiver off/transmit on ???
    }
    
    void loop()                         ********** send "Hello World" once a second
    {
      const char text[] = "Hello World";
      radio.write(&text, sizeof(text));
      
      delay(1000);
    }
    
    
    
    
    *******************************************************************************************
    
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    
    RF24 radio(7, 8);
    
    Same as sending above
    
    *******************************************************************************************
    
    const byte rxAddr[6] = "00001"; *********** setting data in an array location ??? (purpose unknown at present)
    
    void setup()
    {
      while (!Serial);
      Serial.begin(9600);   *********** setting up the serial port
      
      radio.begin();        *********** starting up the radio
      radio.openReadingPipe(0, rxAddr); ************ open up the read function ???
      
      radio.startListening();   *********** start listening for data
    }
    
    void loop()
    {
      if (radio.available())
      {
        char text[32] = {0}; ************ clear the receive buffer 
        radio.read(&text, sizeof(text)); ************ put received data into the "text" array
        
        Serial.println(text); ************ print the data ( i'm assuming this is similar to printing to the P1 debug terminal )
      }
    }
    

    There are most likely objects in the OBEX to perform similar functions to the SPI.h, nRF24L01.h, and RF24.h code. Looking at the library code will also help.

  • Thanks, I will start googling the libraries. Will the Arduino code open on notepad.exe?
  • kwinnkwinn Posts: 8,697
    Thanks, I will start googling the libraries. Will the Arduino code open on notepad.exe?

    I was using the text editor that comes with Linux Mint to paste the code you posted and add the comments so notepad should work.
  • Thanks
  • kwinnkwinn Posts: 8,697
    Don't see any actual code there, but it's a moot point anyway. You will need to use one of the SPI objects in the OBEX. I will look them over and see what may be suitable.
  • kwinnkwinn Posts: 8,697
    If you go to the OBEX and search for "nrf" you will find 3 drivers. Two for nRF24L01 and one for nRF2401. One of them may work for you "as is", and if that is not the case they will at least provide a starting point. No time now, but I will take a look at the code this evening.
  • Thanks, man. I will check it out when I have time(school is backing up on me).
Sign In or Register to comment.