Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no connection from pi pico to arduino #43

Closed
skeyvin opened this issue Sep 13, 2022 · 7 comments
Closed

no connection from pi pico to arduino #43

skeyvin opened this issue Sep 13, 2022 · 7 comments

Comments

@skeyvin
Copy link

skeyvin commented Sep 13, 2022

i have this on the pico

print("Hello World!")
import time
import struct
import board
import busio
import digitalio
from digitalio import *
from circuitpython_nrf24l01.rf24 import RF24
spi = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4)
    # change these (digital output) pins accordingly
CE_PIN = DigitalInOut(board.GP1)
CSN_PIN = DigitalInOut(board.GP0)
nrf = RF24(spi, CSN_PIN, CE_PIN)
nrf.pa_level = -12
address = [b"\xe1\xf0\xf0\xf0\xf0", b"2Node"]
nrf.open_tx_pipe(address[0])  # always uses pipe 0
nrf.open_rx_pipe(1, address[1])
nrf.data_rate = 250
nrf.channel = 100
nrf.listen = False
while True:
    nrf.send(b"u")

and i have checked the wiring.
and i have this

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8);
const byte address[5] = "00001";
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
if(!radio.begin()){
  Serial.print("biggus dookes");
}
Serial.println("ready");
radio.setChannel(100);
  radio.openReadingPipe(1, 0xE1F0F0F0F0);
  radio.openWritingPipe(0xE2F0F0F0F0);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  radio.setDataRate(RF24_250KBPS);
 // radio.setAutoAck(true);
 // radio.powerUp();
}

void loop() {
  if (radio.available()){
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.print(text);
    Serial.print("\n");
    
  }
}

on the arduino.
they work fine if i use the c++ version for the pi pico but when i use the circuitpython version i cant get any data to the arduino.

@2bndy5
Copy link
Member

2bndy5 commented Sep 13, 2022

set

nrf.dynamic_payloads = False

There are a few differences between the C++ and CirPy libs outlined at the bottom of the examples' doc.

@skeyvin
Copy link
Author

skeyvin commented Sep 13, 2022

set

nrf.dynamic_payloads = False

There are a few differences between the C++ and CirPy libs outlined at the bottom of the examples' doc.

set it to

import time
import struct
import board
import busio
import digitalio
from digitalio import *
from circuitpython_nrf24l01.rf24 import RF24
spi = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4)
    # change these (digital output) pins accordingly
CE_PIN = DigitalInOut(board.GP1)
CSN_PIN = DigitalInOut(board.GP0)
nrf = RF24(spi, CSN_PIN, CE_PIN)
nrf.pa_level = -12
address = [b"\xe1\xf0\xf0\xf0\xf0", b"2Node"]
nrf.open_tx_pipe(address[0])  # always uses pipe 0
nrf.open_rx_pipe(1, address[1])
nrf.data_rate = 250
nrf.channel = 100
nrf.allow_ask_no_ack = False
nrf.dynamic_payloads = False
nrf.listen = False
while True:
    nrf.payload_length = 8
    nrf.send(b"u")

but still no success

@2bndy5
Copy link
Member

2bndy5 commented Sep 13, 2022

   nrf.payload_length = 8

This needs to match whatever you passed to radio.setPayloadSize() on the Arduino side. Based on the code you posted in the OP, you didn't actually call this on the Arduino, so it should be only looking to receive 32-byte payloads.

@skeyvin
Copy link
Author

skeyvin commented Sep 13, 2022

This needs to match whatever you passed to radio.setPayloadSize() on the Arduino side. Based on the code you posted in the OP, you didn't actually call this on the Arduino, so it should be only looking to receive 32-byte payloads.

changed it to

from circuitpython_nrf24l01.rf24 import RF24
spi = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4)
    # change these (digital output) pins accordingly
CE_PIN = DigitalInOut(board.GP1)
CSN_PIN = DigitalInOut(board.GP0)
nrf = RF24(spi, CSN_PIN, CE_PIN)
nrf.pa_level = -12
address = [b"\xe1\xf0\xf0\xf0\xf0", b"2Node"]
nrf.open_tx_pipe(address[0])  # always uses pipe 0
nrf.open_rx_pipe(1, address[1])
nrf.data_rate = 250
nrf.channel = 100
nrf.allow_ask_no_ack = False
nrf.dynamic_payloads = False
nrf.listen = False
nrf.payload_length = 32
while True:
    
    nrf.send(b"u")

and changed the arduino code to

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8);
const byte address[5] = "00001";
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
if(!radio.begin()){
  Serial.print("biggus dookes");
}
Serial.println("ready");
radio.setChannel(100);
  radio.openReadingPipe(1, 0xE1F0F0F0F0);
  radio.openWritingPipe(0xE2F0F0F0F0);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  radio.setDataRate(RF24_250KBPS);
  radio.setPayloadSize(32);
 // radio.setAutoAck(true);
 // radio.powerUp();
}

void loop() {
  if (radio.available()){
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.print(text);
    Serial.print("se\n");
    
    
  }
 
 
  

}

@2bndy5
Copy link
Member

2bndy5 commented Sep 13, 2022

well, if that didn't work, then the addresses assigned to the pipe might be using conflicting endianness.

In python:

address = b"\xe1\xf0\xf0\xf0\xf0"  # written in little endian

In C++:

uint8_t address[] = {0xe1, 0xf0, 0xf0, 0xf0, 0xf0}; // little endian (I think)
uint64_t addr = 0xe1f0f0f0f0; // big endian (I think)

@2bndy5
Copy link
Member

2bndy5 commented Sep 13, 2022

@skeyvin It is more memory efficient in C++ to use an array of bytes (like a c-string but without the NULL terminating byte). The ability to use a uint64_t address in C++ RF24 is officially deprecated, and it uses 8 bytes of memory to store a 5 byte address.

@skeyvin
Copy link
Author

skeyvin commented Sep 13, 2022

Thanks for that kind stranger on the internet. uint8_t in combination with disabling dynamic payload worked

@skeyvin skeyvin closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants