Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: radio.begin(); is not starting in raspberrypi3

Mustafa:

**hi everybody I am trying to send a text from Raspberry 3 to Arduino by nrf24 and When I start this jar in Raspberry Pi 3 i am not getting any error and it says "RF 24 Data Sending" and "Radio Beginning" in the output but radio.begin(); can not working .*


'import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import com.github.stanleyseow.RF24;
import com.github.stanleyseow.rf24_datarate_e;
import com.github.stanleyseow.rf24bcmjavaJNI;

public class GettingStarted {
private static RF24 radio;
private static short ce_pin=22;//GPIO_025
private static short cs_pin = 24;//GPIO_08
private static long spiSpeed = 32;

private static short retriesTime=10;

static {
System.loadLibrary("rf24bcmjava");
}

public static void main(String[] args) throws InterruptedException {

radio = new RF24(ce_pin,cs_pin, spiSpeed/* BCM2835_SPI_SPEED_8MHZ */);
byte[] pipeWrite = {(byte) 0xE8,(byte) 0xE8,(byte) 0xF0,(byte) 0xF0,(byte)
0xE1};
byte[] pipeRead = {(byte) 0xF5,(byte) 0xF5,(byte) 0xF5,(byte) 0xF5,(byte)
0xE1};
System.out.println("not start");
// Print preamble:
System.out.println("RF 24 Data Sending");
System.out.println("Radio Beginning");
// Setup and configure RF radio
/********************************************/
radio.begin();
//Radio can not start
/********************************************/
System.out.println("Radio Began");
radio.setPayloadSize((short)32);
radio.setChannel((short)0x70);
radio.setDataRate(rf24_datarate_e.RF24_1MBPS);
radio.setPALevel((short) rf24bcmjavaJNI.RF24_1MBPS_get());
radio.enableDynamicPayloads();
radio.enableAckPayload();
radio.setAutoAck(true);
// optionally, increase the delay between retries & # of retries
radio.setRetries(retriesTime, retriesTime);
System.out.println("Trying Again");
// Dump the configuration of the rf unit for debugging
radio.printDetails();
System.out.println("Print Details");
/********* Role chooser ***********/
System.out.println("\n ************ Role Setup ***********\n");
/***********************************/
// This simple sketch opens two pipes for these two nodes to communicate
// back and forth.

System.out.println("write pipe opened");
radio.openWritingPipe(pipeWrite);
System.out.println("read pipe opened");
radio.openReadingPipe((short) 1, pipeRead);

//Arduino expects an unsigned long = 4 bytes
//Java long = 8 bytes. We have to use a int = 4 bytes
//Caution: All primitive datatypes in Java (ByteBuffer buf = ByteBuffer.allocate(http://ift.tt/2Ae6iUs);
System.out.println("Data is ready");
buf.order(ByteOrder.LITTLE_ENDIAN); //Arduino is Little Endian
// forever loop
int counter = 0; //Increment a counter instead of sending the time
while (true)
{
// First, stop listening so we can talk.
radio.stopListening();

// Increment the counter, and send it. This will block until complete
counter++;
System.out.println("Now sending..." + counter);
buf.clear();
buf.putInt(counter);
boolean ok = radio.write(buf.array(), (short)(buf.capacity()));
System.out.println("yazma okeylendi");
if (!ok){
System.out.println("Writing not"+"okey" );
System.out.println("Radio failed.");
}
// Now, continue listening
radio.startListening();

// Wait here until we get a response, or timeout (250ms)
long started_waiting_at = System.currentTimeMillis();
boolean timeout = false;
while ( ! radio.available() && ! timeout ) {
System.out.println("Radio Passive");
if (System.currentTimeMillis() - started_waiting_at > 200 )
timeout = true;
}


// Describe the results
if ( timeout )
{
System.out.println("Failed, response timed out.");
}
else
{
// Grab the response, compare, and send to debugging spew
int response;
buf.clear();
radio.read( buf.array(), (short)(buf.capacity()));
response = buf.getInt();
// Spew it
//System.out.format("Got response %d,\n",response);
}

// Try again 1s later
// delay(1000);

Thread.sleep(1000);


} // forever loop
}
}

*How can i solve this.

Please help me. Thanks.*



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: radio.begin(); is not starting in raspberrypi3

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×