Jot Test

UPDATE: Progress on NRF24L01 code for working between PC, Hub, and Robot.

So, here is my attempt at a swarmie build.  Not much here yet, simply a personal build log until I get an iteration cheap enough, then, I'll start incorporating them into the Overlord project.

I have to bow to Bajdi; those little NRF24L01 take a lot more brainpower than simple ole' Bluetooth.  I tried for some time to write my own code that would send and receive bytes to or from the other node.  After a little of hair pulling I gave up and started reading other's code.  I came across Robvio on the Arduino Forums who had some rather nifty code that I left nearly intact.

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

RF24 radio(8,7);
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = {0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

//for Serial input
String inputString = “”; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete

//NRF Packages
byte SendPackage[32];
byte ReceivePackage[32];
boolean sending=0;

void setup(void)
{
//
// Print preamble
//

Serial.begin(9600);
radio.begin();
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
radio.setPayloadSize(32);
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.startListening();
//radio.printDetails();
}

void loop(void)
{
//check for NRF received
NRFreceive();
//check for Serial received (or filled by NRF)
Serialreceive();
}

void serialEvent() {
Serial.println(“Event”);
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == ‘\n’) {
stringComplete = true;
}
}
}

byte NRFsend(String NRFPack = “”){
NRFPack.getBytes(SendPackage, 32);
radio.stopListening();
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
bool ok = radio.write(SendPackage,sizeof(SendPackage));
if (!ok) Serial.println(“NRFerror”);
radio.startListening();
unsigned long started_waiting_at = millis();
bool timeout = false;
while ( ! radio.available() && ! timeout )
if (millis() - started_waiting_at > 200 )
timeout = true;
if ( timeout )
{
Serial.println(“NRFerror”);
}
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
}

void NRFreceive(){
if ( radio.available() )
{
//byte ReceivePackage[32];
bool done = false;
while (!done)
{
done = radio.read( &ReceivePackage, sizeof(ReceivePackage) );
delay(5);
}
radio.stopListening();
inputString = ((char *)ReceivePackage);
stringComplete = true;
radio.write( “1”, 1 );
radio.startListening();
}
}

void Serialreceive(){

if (stringComplete) {
if (inputString.startsWith(“T:”)) {
NRFsend(inputString.substring(2));
}
if (inputString.startsWith(“S:”)) {
Serial.print(inputString.substring(2));
}

inputString <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">""</span>;
stringComplete <span style="color: #333333;">=</span> <span style="color: #007020;">false</span>;

}
}

 

The way this code works is much like a software and serial simulated Bluetooth module.  

To send serial data it goes like this, you type something with a prefix code, T for transmit and S for serial print, and ending with a newline character (\n).

For example, typing the following in the terminal on module A:

  • T:S: My message \n

Will send “My message” to the other module B, then, it will print “My Message” to serial line on the module B.

If you type,

  • T: My message \n

This will transmit “My message” from module A to module B, but it will not be printed to the serial line on module B.  

I’ll let you guys look the code over and tell me if I can improve it for what I’m doing.  Right now, I’ve tested it with some basic Python code to send a serial message to my hub (Arduino Uno and NRF24L01), which relays it to the robot (Arduino Pro Mini and NRF24L01).

 

Public Tinkercad Design

Cost to build

  1. Tower Micro 9g Servo x 2: $5.22
  2. Ball Caster 1/2" Metal x 1: $3.65
  3. Funduino (early Arduino Pro Mini): $4.89
  4. AAA x 4: $1.44
  5. NRF24L01 x 1: $1.31
  6. Compass (HMC5883L): $2.37
  7. 2-56 Threaded 2" Stud x 2: $1.00
  8. 2-56 1 1/2" Screw x 2: $.17
  9. 2-56 Hex Nut x 6: $.23
  10. AAA x Battery Case w/ Switch: 1.05
  11. Helper Board:$1.53
  12. SOT-23-5, 3.3v, .30mA LDO Voltage Regulator x 1: $.57
  13. 1uF 0805 ceramic capacitor x 2: $.20 
  14. 0805 4.7k resistor x 2: $.03
  15. 0805 330-860oh resistor x 1: $.03 
  16. 0603 LED (red, green, yellow) x 1: $.09
  17. Right Angle header x 8: $.05
  18. Straight Header x 26: $.08

Total (approximate): $23.95

Videos

Designing the build in Tinkercad:

Converting Tower Pro 9g Servo to Full Rotation for Motors:

Cutting Out the Build:

Putting the Pieces Together:

Making the Little Warmie Helper:

 


This is a companion discussion topic for the original entry at https://community.robotshop.com/robots/show/jot-test