Puck.js Connect to Adafruit Feather Board #4347
Replies: 1 comment
-
Posted at 2024-06-07 by @fanoush The device name is often sent in scan response packet that Puck.js must actively ask for for every device. That is the Posted at 2024-06-07 by @gfwilliams Do you know (maybe from the adafruit app, or the NRF connect app) what the device's MAC address is? That way you can at least try and track down which the correct device is - or you can even just specify it manually using the MAC address. In what you posted all I see is Could you feather still be connected by BLE to your phone/PC? If so it won't be advertising. Posted at 2024-06-07 by user158306 Thank you for the response - I've updated the puck.js code to include the "active:true" below, and I've included a full list of the devices that are seen by the puck.
Posted at 2024-06-08 by user158306 Ok, I think I am getting closer. I'm just really trying to navigate how the two different libraries (Arduino and Espruino) talk to each other. I have the following code on the puck.js. I can see and connect to the Arduino Adafruit Feather board with the puck on a button push.
The code on the Arduino Feather is below. In the Serial output, when I click the puck button it shows the Device Connected in the output - but I can not for some reason get the UART message to be passed between the puck and the Arduino board. I'm sure it's something simple I'm missing - so sorry if this is an easy one.
Posted at 2024-06-10 by @gfwilliams Ahh - ok. Right, well, first off to detect the feather, using MAC address is great if it's just one-off. You can see it reports as:
So you can do:
To return any device advertising the Nordic UART service. What you're doing with So your code would be more like:
Posted at 2024-06-10 by @gfwilliams I should add I'm not 10o% sure whether that's the right code for the Feather either... I'd have expected the Posted at 2024-06-10 by @fanoush There are plenty of such Feather boards There are even modules just with the nrf51 to be connected over UART or SPI https://www.adafruit.com/search?q=ble+friend (there is also Also I see in the Arduino code that the Posted at 2024-06-10 by user158306 Hi fanoush and Gordon, Thank you for your help in trying to connect the puck with the Feather. The board that I am using is: https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/using-with-arduino-ide I can get the puck and feather to "connect" to each other - when I push the button on the puck the Bluetooth LED on the Feather lights up - which means it is making a connection. Figuring out how to exchange/communicate UART data between them after they are connected seems to be tricky. When I include the code above I get the following error:
Posted at 2024-06-10 by user158306 I've got the Puck to connect and return the promise using requestDevice. I just don't see the result on the Arduino board. I know they connect.
This is my arduino code with the libraries included.
Posted at 2024-06-11 by @gfwilliams Sorry, that's my fault for some bad example code. Glad you got it sorted with requestDevice. One thing I do notice is you do So you could try Posted at 2024-06-11 by @fanoush
you should perhaps work with the
inside the loop could get the data? Posted at 2024-06-11 by user158306 Thank you both for the support! I put in an update using fanoush's recommendation on the Feather.
Posted at 2024-06-11 by @fanoush What about trying some bleuart example from adafruit? Attachments: Posted at 2024-06-11 by @gfwilliams You could also try connecting to the feather with the 'nRF Connect' Android/iOS app and writing to the characteristic directly - that way you can rule out Espruino as being the problem Posted at 2024-06-11 by user158306 Lots of progress - thank you both for your patience and guidance!!! In the process, I'm learning a lot about the environments (BLE, Aurduino, and Espruino). I have the Puck and the Feather talking to each other!!! I'm not sure EXACTLY what made it happen, but I'll go with it Here is what I have on the Puck that works.
Here is what I have on the Feather. I am able to read the serial and then I have an if statement to check the value and if it matches then it triggers another function. This is just a simple example to test it, but it works.
The only issue is that it disconnects after it sends the info. How would I be able to persist the connection? I tried the below. It connects to the board but doesn't write to the serial like "requestDevice " did.
Posted at 2024-06-12 by @gfwilliams Glad you got it working! If you look at https://www.espruino.com/BLE+UART#receiving-evaluating there are some other examples though. Probably most useful is:
Posted at 2024-08-16 by user158306 Thank you so much for all of your support on this! I've been making further progress in other areas and trying to get the arduino board and the puck to talk to each other. What I can't seem to figure out - after looking at the tutorials and digging through the forums is how to receive a ble_art update from the arduino board. I have seen the "eval" function and I've seen the examples with the web and python implementations - but how do those get adapted for the puck? sorry, I have a feeling this is a very basic question, but I can't seem to find the right direction. Posted at 2024-08-16 by user158306
Posted at 2024-08-17 by user158306 One of the things I am stuck on with the ble_uart module, is what does the puck code look like if I already have an established connection. When I look at the source of the module, and most of the examples, they show requestDevice as the default. But when I try to use the standard ble_uart, I am getting errors that I am already connected or if I do something like :
I get a "Uncaught Error: Unhandled promise rejection: Error: Function "write" not found!" Here is all of the testing code:
Posted at 2024-08-27 by @gfwilliams I feel like maybe you're getting code mixed up somewhere? On the BLE UART page it gives you some examples, but you're doing something a bit different: https://www.espruino.com/BLE+UART#receiving-evaluating For example you're doing So your code should look something like:
If you want to stay connected you could hang onto the Posted at 2024-09-25 by user158306 Thanks for this info Gordon - and apologies for the delay in getting this updated. I think I'm really stuck on the eval aspect of how to receive data to the Puck.js. I'm sure I'm just missing something trivial in the library that once I see it, it will be so obvious. I tried to reduce the code to just a basic - send a simple vale "1" to the Arduino board, and once the board receives a value of "1" return back to the Puck a value of "1" to confirm the data. Puck Code:
Arduino Code:
I am able to send the value to the Arduino board, and can trigger a function on the Arduino board based on the value sent by the Puck (but usually only when I use the ble uart simple). But am not able to get a value back. I usually receive a CCCD error. Any direction would be greatly appreciated! Posted at 2024-09-26 by @gfwilliams On the Puck, maybe try:
There were a few issues on the Puck side:
Posted at 2024-09-26 by user158306 Hi Gordon - Thank you for the reply. When I try this, I am getting a "Uncaught Error: Unhandled promise rejection: CCCD Handle not found" error from the Puck. The Puck does connect to the Arduino board. Then it seems to lock/hold a connection to the board (which is because of not having the disconnect), but the Arduino board doesn't register the Puck writing (arduino receiving) the value to the board, so the return promise is never handled. Does that make sense? Under the Arduino Serial output should be the lines Attachments: Posted at 2024-09-27 by @gfwilliams Ahh, ok, thanks! So the When a device provides a 'characteristic' that provides notifications when its value changes, it's supposed to have another characteristic linked to that one called a CCCD that allows you to switch those characteristics on or off. It would seem that the Bluefruit is providing the UART TX data characteristic, but somehow the CCCD that's supposed to be for it can't be found by Espruino. Without me having a Bluefruit here it might be a bit hard for me to track this down. However looking back, it seems that you didn't really want the two-way communication anyway? You just wanted to be able to send some data without disconnecting? In that case we can just modify the code from https://www.espruino.com/modules/ble_simple_uart.js slightly and include it in your folder directly:
Just tried this - not on a feather though, and it works well for me - and automatically reconnects if there's no connection Posted at 2024-09-27 by user158306 Hi Gordon, thank you again for spending time helping me with this. I would like to be able to communicate back and forth between the Arduino and the Puck. Is there something that I can share from the Bluefruit that would help? When I use:
I am receiving the error "Uncaught Error: Unhandled promise rejection: CCCD Handle not found" But if I use
The puck will write "1" to the feather. Posted at 2024-09-27 by user158306 I'll try to add as much code and images as possible to see what might help figure this out. Here is my bare bones Arduino Code. It should receive the value from the Puck and then if it matches, send a value back.
The first image is the Serial response. This is the code I have for the Puck.
The 2nd image is the output I receive. Even if I move the TX handle to before the RX , I still get a CCCD error. I also just added log to the Primary, RX, and TX return so that we can see what is being returned.
Attachments: Posted at 2024-09-30 by @gfwilliams Yes, you'd expect simple_uart to work because that's not trying to get the CCCD characteristic. Please could you try running this? It should dump all the info Espruino knows about the device:
But also if you could run Posted at 2024-09-30 by user158306 Hi Gordon - thanks so much for all of your support! This is what the Puck returns after connection:
I've attached all of the pictures from nRF Connect. Attachments: Posted at 2024-09-30 by @gfwilliams Thanks! So I've been trying to track this down, and as far as I can see, the issue is that the Bluefruit isn't putting the CCCD handle right after the characteristic, which is what Espruino is expecting (and which seems to work on most other devices). Please can you try changing the code as follows:
Unfortunately NRF connect doesn't show what the 'handle values' are for the characteristics, and I don't think Adafruit publish the source code for their Bluefruits so I can't actually see what's going on. If 35 doesn't work, maybe try 34? failing that, 38 or 39. Sorry it's such a mess - but this is the first time in 5+ years it's come up and it feels like the Bluefruits are doing something a bit different to the way other devices do. Posted at 2024-09-30 by @fanoush BTW, you can see all handle numbers with gatttool in linux, see e.g. this blog post https://cxiao.net/posts/2015-12-13-gatttool/ Posted at 2024-10-01 by user158306 Hi Gordon! Thank you for your patience and support with my project. Good news, we have success!!! I'll post the final code below for anyone that is having a similar issue with the BlueFruit Feather. What seemed to make it finally work were two things - 1) The direct setting of the CCCD handle to 35. 2) Moving the TX up so that it registers the notification before sending the value to the Arduino board. In the code below I've also added the buffer conversion, and a disconnect once it receives the correct value so that you can push the Puck to start the process again. Again, thank you so much for your patience and support!
Posted at 2024-10-02 by @gfwilliams Great! Glad it's working now! I made a change to the firmware so if it doesn't find the CCCD in the normal place it looks one after. So please could you try installing a 'cutting edge' firmware and removing the Posted at 2024-10-05 by user158306 Hi Gordon, Posted at 2024-10-07 by @gfwilliams Thanks! Literally all you need to do for now is update to the latest (cutting edge) firmware, and then try and run the code you posted above but without the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2024-06-07 by user158306
Hi! I am new to Arduino and Puck and Bluetooth programming. This is probably a very simple thing - but I am really struggling to make this work.
I have a Puck and an Adafruit Feather BLE board that I am jut trying to send signals between. I have the Arduino board setup and I know it is broadcasting. I have the Puck setup and I can run the findDevice() to search for devices (and it creates a list of available devices).
I have the board renamed - say to "Splitz" - and my phone and Mac see the board as renamed as "Splitz" if I connect to it. But I can not for the life of me get the Puck to "see" the board.
This is what I am using to scan for devices on a Puck button push.
The below is some of what returns. I know I just don't know what I am looking for in the returned data to parse out which one is the Feather board. The code says it is 0x00D6 hardware? I can see both devices on the Bluefruit App as well and can connect and UART to them both. I'd like to be able to send signals from the puck to the Board and vice versa.
Any help in the right direction would be amazing!!
Beta Was this translation helpful? Give feedback.
All reactions