Arduino library

327 views
Skip to first unread message

zwanni

unread,
Feb 12, 2021, 6:05:15 AM2/12/21
to Unijoysticle
Hello,

and congratulations for this great projekt at first. I was searching for a Arduino based ESP32 bluetooth library to use a gamepad controlling a robot for example. Actually I found something for playstation controllers, but nothing close like this projekt. The ESP32 became a very common Controller for DIY stuff especially with Bluetooth classic suppport there are not many options. I'm not sure how much you would be interested in, and how much effort it will take to get a running code where you can just use the gamepad inputs to control whatever you want within your arduino projekt, but maybe it would also push your project and visions. I'm sure many noobs like me would be interested.
I think the code is almost completly there, but it is to complex for me to get it work on my own.

take it just as idea, it's a great project anyways.

thanks
zwanni

Ricardo Quesada

unread,
Feb 12, 2021, 10:19:47 AM2/12/21
to zwanni, Unijoysticle
Thanks Zwanni,

I'm not sure I fully understood your idea.
Could you add a concrete example of what you want? thanks
> --
> You received this message because you are subscribed to the Google Groups "Unijoysticle" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to unijoysticle...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/37a6d7d4-3425-4e10-a51d-cc3026c1dbdfn%40googlegroups.com.

zwanni

unread,
Feb 12, 2021, 12:24:41 PM2/12/21
to Unijoysticle
hi ricardo,

your gamepad implementation for the ESP32 is very interesting for many projects. At the moment it's a specific firmware for your retro gamepad converter project. 
The hobby builders aren't in deep enough in this stuff like you and use the Arduino IDE to programm their projects. I don't know if you ever looked into the Arduino bubble, so let
me shortly explain.
There is Arduino Hardware and a Arduino IDE which you surely heared about. Out of the box it's very easy to programm some standard microcontrollers. If you buy a ESP32 dev
board, you just have to install the Hardware definitions and you are also ready to go. Your write a c/c++ based code on a low level, click upload and it compiles and runs the code on your board.
There are tons of librarys for any sensors, displays, and so on. You just install a library and (most time) it works for any Arduino supportet controller plug and play. Maybe real
developers don't like Arduino because it's so easy and their work is less appreciated. But the real work exists anyways in good libraries. 

Your work would be a very nice library to use gamepads on many ESP32 projects. The user just would include your code and is able to control whatever...., with the favorite gamepad.
The 'only' work to do would be to, remove the joystick output stuff of your project, make the button events available, add a choose/include for the desired gamepad,
and make the code from standalone to compilable with the Arduino IDE.
I'm not sure how much work this would be, but because you just programmed it for the ESP32 in C, most work has been done anyways. 


I hope this is a bit helpful to understand.

Ricardo Quesada

unread,
Feb 12, 2021, 3:08:26 PM2/12/21
to zwanni, Unijoysticle
Thanks Zwanni,

Actually the firmware (now called bluepad32) is not specific to any project.
I made quite a few changes recently so that it is easy to use in any
ESP32 board.
https://gitlab.com/ricardoquesada/bluepad32

Perhaps adding Arduino as a "platform" is that you want?
There are already 4 platforms supported. Take a look at the documentation:
https://gitlab.com/ricardoquesada/bluepad32/-/blob/master/README.md

Here are the steps to add a new platform:
https://gitlab.com/ricardoquesada/bluepad32/-/blob/master/docs/adding_new_platform.md

Although adding "Arduino" as a new platform might be more complex...
or not... perhaps it is just a matter of creating some header files.
I don' t have the time to work on that, but if you want to do it and
need help, let me know. Thanks.
> To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/807b97bd-0fb9-42c6-8889-4ecbc8ebf850n%40googlegroups.com.

zwanni

unread,
Feb 13, 2021, 5:45:13 PM2/13/21
to Unijoysticle
hi,

yes, I already found all your informations and tried it on myself and spent many hours the last days....

I did the following steps:
    - I had issues with the file structure of the btstack. I don't know why, but I had to reorder the files to the right path to get the includes correctly.
    - removed make-, config-, and other unnecessary files (I need the pure source code. The Arduino IDE does the whole compiling internally)
    - added a Bluepad32 C++ file which replaces uni_main and uni_main_esp32 files and setup a static configuration to test on
    - built the basic Arduino library structure
    - I'm testing with the Airlift setup just harcoded and a 8bitdo SF30 Pro gamepad

after some/many struggeling I was able to compile the project.

I turned on any debug infotmation and got this as output:

[00:00:03.012] LOG -- btstack_run_loop_freertos.c.309: run loop init, task 0x3ffc0774, queue item size 8
[00:00:03.012] LOG -- main.c.284: transport_register_packet_handler
[00:00:03.017] LOG -- btstack_tlv.c.48: TLV Instance 0x3f4066a8
[00:00:03.023] LOG -- le_device_db_tlv.c.159: num valid le device entries 0
Platform: Adafruit AirLift
Gap security level: 2
[00:00:03.033] LOG -- l2cap.c.3714: L2CAP_REGISTER_SERVICE psm 0x13 mtu 128
[00:00:03.040] LOG -- l2cap.c.3714: L2CAP_REGISTER_SERVICE psm 0x11 mtu 128
[00:00:03.047] LOG -- hci.c.3315: hci_power_control: 1, current mode 0
[00:00:03.053] LOG -- main.c.221: transport_init
[00:00:03.058] LOG -- main.c.237: transport_open
[00:00:03.062] LOG -- main.c.252: transport: esp_bt_controller_init failed
[00:00:03.068] LOG -- hci.c.3232: HCI_INIT failed, turning Bluetooth off again
[00:00:03.075] LOG -- hci.c.4840: BTSTACK_EVENT_POWERON_FAILED
[00:00:03.081] LOG -- hci.c.3325: hci_power_control_on() error -1

I'm not sure if I broke anything in the btstack because I reordered so many files.
Maybe you have a quick answer where to search with your experience. 

thanx

Ricardo Quesada

unread,
Feb 13, 2021, 8:46:08 PM2/13/21
to zwanni, Unijoysticle
The first thing that I would try is to
a) try one of the pre-compiled firmwares (you can try any... airlift
or unijoysticle) in your board... and see if that works.
b) If that works, then try compiling your own (unijoysticle or
airlift) firmware and see if that works.
c) If so, then try adding the Arduino files...

If a) and b) works, but not c), then clearly it has to do with the
arduino files.
If a) doesn't work , then probably something is wrong with your board:
which one are you using?
if b) doesn't work, then probably you have to fix your tooling...
perhaps wrong esp-idf version?
> To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/27dc13e2-b780-4abe-9b67-0d4d8c7e8488n%40googlegroups.com.

zwanni

unread,
Feb 14, 2021, 5:27:25 PM2/14/21
to Unijoysticle
The pre-compiled and self compiled firmwares are fine on my board, so here we are good.

I tested as well on which versions of esp-idf the code works correct.
Up to v4.2.x it workss fine, on versions above it doesn't work correct, but I don't get the
error like in my version.

The tricky thing is that I tried to is to get the btstack right into the project path and not in
the esp-idf structure. The reason for this is, that I use a Hardware library for the esp32 to
work with the Arduino IDE which I don't want to touch, otherwise the whole idea looks a bit
senseless. I don't know thich esp-idf version they use at the moment.

The most likely case is for me now that I didn't get the btstack correct into the project,
which I can test if I try the same in the original project.
If I got the similar error then, I know where I have to work on. If it runs, it's the worst
scenario, because then I would need to build the ESP32 hardware library as well, which
was not my intention.

thats it for now. If I get it to work, I maybe have further 'real' questions.

just for information...

Ricardo Quesada

unread,
Feb 14, 2021, 5:50:38 PM2/14/21
to zwanni, Unijoysticle
a few things to keep in mind:

- make sure that the btstack_config.h is installed correctly
- make sure that esp-idf firmware is configured correctly (make menuconfig)

The project "nina-fw" has arduino + esp32... that could be a good
starting point.
https://github.com/arduino/nina-fw
> To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/13e72774-f981-4c08-b6cb-b9f83a31f65bn%40googlegroups.com.

Ricardo Quesada

unread,
Jul 18, 2021, 7:59:21 PM7/18/21
to zwanni, Unijoysticle
Update:

I've just released v2.2 which has Arduino support for boards that have
NINA boards: e.g Arduino Nano RP2040 Connect, Nano 33 IoT, etc...
(this not exactly the same as supporting the Arduino ESP32 core).

For those interested in it:

- Arduino library is here: https://gitlab.com/ricardoquesada/bluepad32-arduino

- Firmware for NINA is here:
https://gitlab.com/ricardoquesada/bluepad32/-/releases

zwanni

unread,
Jul 19, 2021, 3:46:02 AM7/19/21
to Unijoysticle
oh wow thats a great step. I tried a lot to get it running on the ESP32, but it was to complicated for me on to many ways.

was it easier to develop for these boards, or why did you choose them?

Ricardo Quesada

unread,
Jul 19, 2021, 9:50:59 AM7/19/21
to zwanni, Unijoysticle
Yes, it is easier to port it first to the Arduino boards that have the
NINA co-processor.
This is because the NINA co-processor is an ESP32, which is used
mostly for WiFi.

The RP2040 and NINA talk to each other using SPI.
For example, RP2040 sends NINA a message
- "tell me all the available WiFi networks",
- "connect to WiFI XXX using password NNN".
- "establish an HTTP connection to this URL"
- etc...


What I did was to replace the original firmware that runs in NINA with
Bluepad32.
The RP2040 and NINA still talk to each other using SPI, but now the
messages are:
"send me the data of the connected gamepads"
"set rumble x,y for gampad 1"
etc...
> To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/182accdd-4a74-4d53-8407-0e07a3d08374n%40googlegroups.com.

zwanni

unread,
Dec 15, 2021, 4:28:57 AM12/15/21
to Unijoysticle
I'm still following your Project, but I'm not sure if you are on the right way with the arduino portation.
Maybe I'm completly wrong, but I will try to explain how the ways should be.

The Espressif guys have built a full arduino extention based on ESP-IDF 4.4 at the moment.
in the settings of the arduino IDE for aditional boards. Then under Tools>Board:...>Boards Manager you will
find the esp32 extention to install. 
With this base everbody programs their ESPs in the Arduino IDE.

The second thing you need is the bluetooth stack which you are using!?!
I think there is also a library for arduino from the bluekitchen btstack.

I think there is missing a properties file to be recognised as library.

I'm not sure if this helps and if it's just easy to use like it sounds, but that would be the easiest way
to start from in my opinion.
The need is to program a arduino library which is based on this basics.

zwanni

unread,
Dec 15, 2021, 5:16:07 AM12/15/21
to Unijoysticle
ok, the btstack is for using with a bluetooth module I think, so that's not what I thought.

zwanni

unread,
Dec 15, 2021, 6:15:25 AM12/15/21
to Unijoysticle
okay I read a bit more in your " Bluepad32 firmware for Arduino" documentation and found your path to go.
Option C is exactly what is needed. The other two options are nearly useless, because Arduino users won't understand.
Anyone who is able to program the controler like this doesn't use Arduino so it excludes each other.
I hope you will make progress in this part :)

Ricardo Quesada

unread,
Dec 15, 2021, 9:58:48 AM12/15/21
to zwanni, Unijoysticle

 The other two options are nearly useless, because Arduino users won't understand.
Anyone who is able to program the controler like this doesn't use Arduino so it excludes each other.

:) I think you are underestimating the Arduino users. Some users might be "newbies",  but others are advanced programmers that just prefer Arduino because of the library ecosystem (just to name one feature).

In any case, you should try using this template, which has Arduino + Bluepad32 already setup:

It has some limitations, like you cannot use the Arduino IDE, so integrating it with other libraries requires a few extra steps. But everything is documented in that link.


 

zwanni

unread,
Dec 15, 2021, 12:37:14 PM12/15/21
to Unijoysticle
I know, but the truth is that I would buy a Playstation controller first because there are librarys for them.
In my personal case it's not comfortable enough to use, so I will wait for option C :)

Reply all
Reply to author
Forward
0 new messages