kramer65
Posts: 40
Joined: Mon Mar 18, 2013 2:59 pm
Location: Amsterdam

How to use nRF24 via CH340T serial-to-USB converter?

Sat Oct 12, 2019 6:37 pm

Using a raspi 3B I'm building an autonomous boat to which I currently connect over wifi. I now want to make it go beyond the range of the wifi so I want to use the nRF24 chips because they have a larger range. I bought two of these, which combine the nRF24 chip with a CH340T serial-to-USB converter. I need to connect the raspi in the boat to my laptop on land (running Ubuntu), and since my laptop doesn't have any GPIO pins I want to make them work through USB.

So I found this RF24 library. I compiled and installed it on the raspi, including the Python bindings (in Python I can do an `import RF24` so that seems to work). I then found this example code of how to make it work. Unfortunately that example uses the GPIO pins to connect to the nRF24 chip.

And from here I'm kinda lost.

Does anybody know how I can make that example work through the CH340T serial-to-USB converter? All tips are welcome!

User avatar
clicky
Posts: 416
Joined: Thu Oct 25, 2012 7:34 am

Re: How to use nRF24 via CH340T serial-to-USB converter?

Sat Oct 12, 2019 8:17 pm

I'm currently (I mean - actively - today!) using nRF24L01 connected directly to SPI of RPi. With Raspberry Pi you really don't need USB adapter.

There are plenty of other examples all over the internet :)

BTW Right now on my desk I can see 4 nRF24L01 connected - 2 to 2 Raspberry Pis and 2 to ATmega328p uControllers...

I think I started with this post (http://hack.lenotta.com/arduino-raspber ... -nrf24l01/) or something very similar to it. I even adopted their colour scheme...

kramer65
Posts: 40
Joined: Mon Mar 18, 2013 2:59 pm
Location: Amsterdam

Re: How to use nRF24 via CH340T serial-to-USB converter?

Sun Oct 13, 2019 12:37 pm

@clicky

Thanks for your response, and I understand that it works through GPIO. The thing is that I want to use nrf24 to communicate between my laptop and my raspi. And since my laptop doesn't have GPIO PINS I want to use usb to connect to the nrf24 on both my laptop and the pi (to keep code portable).

Would you have any hints on how to make it work through the CH340T serial-to-USB converter?

User avatar
mikronauts
Posts: 2732
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How to use nRF24 via CH340T serial-to-USB converter?

Sun Oct 13, 2019 1:22 pm

The nrf24l01 requires an spi port.

The chg340 usb to serial adapter does not provide an spi port.

Use an arduino as a usb to spi adapter, you can write code for that.

Note that there are some ftdi usb to spi adapters.
kramer65 wrote:
Sun Oct 13, 2019 12:37 pm
@clicky

Thanks for your response, and I understand that it works through GPIO. The thing is that I want to use nrf24 to communicate between my laptop and my raspi. And since my laptop doesn't have GPIO PINS I want to use usb to connect to the nrf24 on both my laptop and the pi (to keep code portable).

Would you have any hints on how to make it work through the CH340T serial-to-USB converter?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
clicky
Posts: 416
Joined: Thu Oct 25, 2012 7:34 am

Re: How to use nRF24 via CH340T serial-to-USB converter?

Sun Oct 13, 2019 1:32 pm

Huh - my previous post has gone missing. Never mind - gist was as following:

I think (*think*) serial here is used instead of SPI - actually adapter sends everything it received from serial to SPI relaying back all (in turn) received back from SPI(*)

Also, one of control serial lines CTS/RTS or DTR/ DSR (virtual in this case) is used as required CS on nRF24L01 side.

So, code that would use SPI to send/receive data - now needs to use serial and control line to control nRF2401.

(*) SPI uses same operation for sending and receiving data. So I suspect that when you send, let's say, 6 bytes (to get read pipe address) you get 6 bytes back. For each sent byte you get one back as SPI would do.

User avatar
mikronauts
Posts: 2732
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How to use nRF24 via CH340T serial-to-USB converter?

Sun Oct 13, 2019 6:17 pm

spi requires a clock signal, which is NOT available on a serial port.
clicky wrote:
Sun Oct 13, 2019 1:32 pm
Huh - my previous post has gone missing. Never mind - gist was as following:

I think (*think*) serial here is used instead of SPI - actually adapter sends everything it received from serial to SPI relaying back all (in turn) received back from SPI(*)

Also, one of control serial lines CTS/RTS or DTR/ DSR (virtual in this case) is used as required CS on nRF24L01 side.

So, code that would use SPI to send/receive data - now needs to use serial and control line to control nRF2401.

(*) SPI uses same operation for sending and receiving data. So I suspect that when you send, let's say, 6 bytes (to get read pipe address) you get 6 bytes back. For each sent byte you get one back as SPI would do.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

kramer65
Posts: 40
Joined: Mon Mar 18, 2013 2:59 pm
Location: Amsterdam

Re: How to use nRF24 via CH340T serial-to-USB converter?

Mon Oct 14, 2019 6:51 am

mikronauts wrote:
Sun Oct 13, 2019 1:22 pm
The nrf24l01 requires an spi port.

The chg340 usb to serial adapter does not provide an spi port.

Use an arduino as a usb to spi adapter, you can write code for that.

Note that there are some ftdi usb to spi adapters.
Are you suggesting that even though they sell the nrf24 together with the CH340T adapter (they even arrive in the mail attached to eachother), it is impossible to let them work together?

User avatar
clicky
Posts: 416
Joined: Thu Oct 25, 2012 7:34 am

Re: How to use nRF24 via CH340T serial-to-USB converter?

Mon Oct 14, 2019 7:46 am

LOL - too much disinformation floating here...
mikronauts wrote: spi requires a clock signal, which is NOT available on a serial port.
Of course it does and µController on CH340T board will provide one. I was never saying that TX and RX lines from serial are directly connected to MOSI and MISO lines :P Of course you have microcontroller which would (my best guess) on each received byte over serial send one over SPI, collect result and send it back.

As I said - only issue where is how to handle CSN pin.

Also, I search internet for you and some people suggest that µController that does USB on one side and SPI on the other might have code to pretend it is a modem and corresponds to AT commands (which AT commands, I've no idea except they were mentioning AT+RXA=... and AT+TXA... to set pipe addresses). This definitively needs far more digging...


User avatar
mikronauts
Posts: 2732
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How to use nRF24 via CH340T serial-to-USB converter?

Mon Oct 14, 2019 1:24 pm

if the board provides a microcontroller in addition to the chg340 usb to serial chip, it could be programmed (my first email suggested using an arduino) to do the serial to spi conversion

clicky wrote:
Mon Oct 14, 2019 7:46 am
LOL - too much disinformation floating here...
mikronauts wrote: spi requires a clock signal, which is NOT available on a serial port.
Of course it does and µController on CH340T board will provide one. I was never saying that TX and RX lines from serial are directly connected to MOSI and MISO lines :P Of course you have microcontroller which would (my best guess) on each received byte over serial send one over SPI, collect result and send it back.

As I said - only issue where is how to handle CSN pin.

Also, I search internet for you and some people suggest that µController that does USB on one side and SPI on the other might have code to pretend it is a modem and corresponds to AT commands (which AT commands, I've no idea except they were mentioning AT+RXA=... and AT+TXA... to set pipe addresses). This definitively needs far more digging...
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
clicky
Posts: 416
Joined: Thu Oct 25, 2012 7:34 am

Re: How to use nRF24 via CH340T serial-to-USB converter?

Mon Oct 14, 2019 1:42 pm

mikronauts wrote:
Mon Oct 14, 2019 1:24 pm
if the board provides a microcontroller in addition to the chg340 usb to serial chip, it could be programmed (my first email suggested using an arduino) to do the serial to spi conversion
You could probably re-program it - but why since it's already coming with fully implemented solution?

User avatar
scruss
Posts: 2628
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: How to use nRF24 via CH340T serial-to-USB converter?

Mon Oct 14, 2019 3:13 pm

mikronauts wrote:
Sun Oct 13, 2019 6:17 pm
spi requires a clock signal, which is NOT available on a serial port.
If you look carefully at the link the OP posted, it looks like there's a pre-programmed PIC18F on there. That would be doing the SPI to serial thing and be managing the AT commands for programming.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
mikronauts
Posts: 2732
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How to use nRF24 via CH340T serial-to-USB converter?

Mon Oct 14, 2019 3:31 pm

That would do it... the original post only mentioned the chg340 and nrf25l01, which without a uc would be an issue.
scruss wrote:
Mon Oct 14, 2019 3:13 pm
mikronauts wrote:
Sun Oct 13, 2019 6:17 pm
spi requires a clock signal, which is NOT available on a serial port.
If you look carefully at the link the OP posted, it looks like there's a pre-programmed PIC18F on there. That would be doing the SPI to serial thing and be managing the AT commands for programming.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

kramer65
Posts: 40
Joined: Mon Mar 18, 2013 2:59 pm
Location: Amsterdam

Re: How to use nRF24 via CH340T serial-to-USB converter?

Tue Oct 22, 2019 1:04 pm

@mikronauts & @scruss & @clicky

Ok, so after my last message I got kinda lost in the conversation you guys where having. I think I understood from it that the CH340T is only one chip on the USB-dongle-pcb-thing I posted and that the other things on that pcb provide the needed functionality for the nRF24 to be functioning over it. Did I understand that correctly?

So then I'm back at the question where I started: Would you guys know how I can make this example code work through the CH340T serial-to-USB converter I bought, instead of using the GPIO pins that are defined in the example code?

User avatar
clicky
Posts: 416
Joined: Thu Oct 25, 2012 7:34 am

Re: How to use nRF24 via CH340T serial-to-USB converter?

Wed Oct 23, 2019 8:25 pm

I think you'll need to slowly build up your knowledge of nRF24L01 first, then translate it to that board. Hints are here: https://forum.arduino.cc/index.php?topic=410574.30

Unless you find library which is doing same or similar to RF24 library in python. If you do - please share it here! :)

Return to “General discussion”