Hello everyone, I am glad to announce I have finally taken the step and installed Nim to try it. As a python developper, I find it absolutely amazing and will try to think about it for some applications at work!
One of the thing that pushed me over was that I needed a faster language than micropython to programm my esp32 though I didn't want to learn C or C++ just for that. I have red a few things on Nim for embedded devices but I admit I am completely novice to this world and absolutely lost.
I know that Nesper and Nephyr should work but I am not completely sure on how to use them. It seems that nephyr doesn't have conf files for the esp32... I also saw that people managed to use Nim on arduino and platformIO. I have no idea where and how to start. If someone could direct me to some ressources or take some time to explain to me how to get started.
I feel obligated to say again that I am very new to Nim (started 2 days ago!) and with compiled languages in general (and even more on microcontrollers).
Thanks for reading my first post, cheers! :)
Welcome! It can be daunting stepping into compiled languages, especially for embedded.
I'd recommend Nesper. Its based on the esp-idf and is much easier to use than Zephyr.
You should in theory be able to follow one of the examples for Nesper. You'll essentially need esp-idf installed. Nesper just wraps around that. You then need to install nesper with Nimble to get the build tasks working. Then it should be a nimble esp_build call followed by a idy.py flash. One thing that may help is just building and flashing one of the esp-idf example programs, as Nesper just builds on top of esp-idf tooling.
Though they're likely out of date at parts. Feel free to post questions or file issues if something doesn't work.
Thank you for replying that quickly! I'm gonna try Nesper right now and try to get a hello world over serial. I didn't realize that nesper was still active because I didn't think of checking the different branches and the last commits on master are already 2 years old haha
I see in the doc that the ADC is not implemented in Nesper. Is that still the case? Because unfortunately I am going to need it for my project, aswell as DAC (PWM?).
Hello again,
I have been following the installation guide on your github page and having an issue with nimbe esp_setup that throws out this error:
:\Users\[user]\.nimble\pkgs2\nesper-0.6.1-9d526d2ec182747c58d820da1742d7a0d3d4647d\nesper\build_utils\tasks.nim(71, 5) Error: unhandled exception: error running getting Nesper path using: `%#` [ValueError]
nimscriptwrapper.nim(160) execScript
Error: Exception raised during nimble script execution
Do you have any idea what could be the problem? Also, maybe I should publish that as a github issue so people can access it...
Thank you for replying that quickly! I'm gonna try Nesper right now and try to get a hello world over serial.
That's a good place to start!
Note the esp-idf has a bug with their malloc, so depending on how you use the serial it'll crash if you create a new instance a lot. Check the issues someone else resolved with serial port.
I didn't realize that nesper was still active because I didn't think of checking the different branches and the last commits on master are already 2 years old haha
Yah, I still use it but for a project that's pretty stable. I should change the default branch. Surprisingly it's had little bitrot. Recently I updated to support 4.4 and 5.0. @girvo has a PR up for one of the new ESPs as well.
I see in the doc that the ADC is not implemented in Nesper. Is that still the case? Because unfortunately I am going to need it for my project, aswell as DAC (PWM?).
Oh, I'd really recommend not using the ESP32's ADC. Perhaps it's better on the newer RISC-V based models, but it's probably the worst ADC I've ever seen. Go for the ads1115 or similar. Those are handy little chips and really accurate given their cost.
And thanks! I never use nimbe esp_setup so it's probably broken.
Note the downside with WSL2 is flashing the esp32 from it. You might do some googling on how people handle esp-idf on Windows and WSL2.
Oh, it looks like folks have setup ways to attach USB ports to WSL2 linux:
After a good day, I finally managed to flash my ESP with both and esp-idf example and the example from the nesper readme. However, it only worked on WSL2 with esp-idf 4.0 (tried 5.1, 4.4, 4.3 and 4.1 I believe). With all version except 4.0 I had "ninja" errors when compiling :/
I found a janky way to access the COM3 port in WSL2 by using idfx. The problem is that monitoring doesn't work but at least I can flash. I will try the method you sent as it looks way cleaner! I will also retry wiith esp-idf 5.0.
Tomorrow I will download the other Nesper forks because having buttons is quite important for the project I am doing. Tbh, I was already thinking about going away from the esp32-S2 to go to either the esp32-C3 or the NFR52840 as I don't need wifi and efficiency is more important...
I am using the DAC and ADC to measure galvanic skin response (GSR) so I may just pick up a specialized sensor, though the size of it may be a problem...
I just thought of something that is a requirement for me, is there a way to mount an SDCard to store measurements until recovery. I saw some code to handle spi_flash but did not really understand the code, mainly because of the C imports (not yet familliar with how Nim and C interface together). Which procedures should I use to mount the SDCard and write bytes in it in real time? I don't need to read the file because this is done on a computer.
Thank you for your help^!
Hey, I'm the guy working on the branch with the buttons, I've got some more changes I'll try to sync into the PR, but if you want the latest work off my devel branch.
I have just started to do stuff with ADCs and added FFI wrappers for the calibration code, I cannot speak to their accuracy, but at 2am last night in my garden they were reading the soil moisture sensor well enough. 😅
I'm still very new to nim and started using it for the exact same reason as you. I'm in the nim discord server as well, feel free to hit me up there @faldor20
Oh wow, I'm really lucky on my timing then!
It's amazing that you managed to implement the calibration because that is one really nice feature of micropython on the esp32. With that, Nesper will be far more advanced than tinygo. Are you also implementing the DAC at the same time?
May I ask you your background before getting into Nim and maybe some advices?
Sure will join that discord, thx for telling me about it!
I was reinstalling everything cleanly (esp-idf 5.0, USB on WSL2...) to have a more reliable setup. However, now whatever branch of Nesper I use (devel, devel-5.0-fixes, faldor20/devel), I was getting an error while compiling the Nim Code:
/home/vincent/Documents/Nim/MCU/esp32_nim_example/main/setup_wifi.nim(44, 30) Error: type mismatch: got <wifi_event_t, proc (arg: pointer, event_base: esp_event_base_t, event_id: int32, event_data: pointer){.cdecl, noSideEffect, gcsafe, locks: 0.}, typeof(nil)>
but expected one of:
template eventRegister[EVT](evt_id: EVT; evt_handler: esp_event_handler_t;
evt_handler_arg: pointer = nil)
first type mismatch at position: 2
required type for evt_handler: esp_event_handler_t
but expression 'onWifiDisconnect' is of type: proc (arg: pointer, event_base: esp_event_base_t, event_id: int32, event_data: pointer){.cdecl, noSideEffect, gcsafe, locks: 0.}
1 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
expression: eventRegister(WIFI_EVENT_STA_DISCONNECTED, onWifiDisconnect, nil)
stack trace: (most recent call last)
/tmp/nimblecache-201274792/nimscriptapi_2043490750.nim(187, 16)
/home/vincent/.nimble/pkgs/nesper-#devel/nesper/build_utils/tasks.nim(244, 11) esp_compileTask
/home/vincent/.choosenim/toolchains/nim-1.6.12/lib/system/nimscript.nim(293, 7) selfExec
/home/vincent/.choosenim/toolchains/nim-1.6.12/lib/system/nimscript.nim(293, 7) Error: unhandled exception: FAILED: /home/vincent/.choosenim/toolchains/nim-1.6.12/bin/nim c --path:/home/vincent/Documents/Nim/MCU/esp32_nim_example/src --nomain --compileOnly --nimcache:main/nimcache -d:NimAppMain -d:ESP_IDF_V5_0 /home/vincent/Documents/Nim/MCU/esp32_nim_example/main/main.nim [OSError]
Error: Exception raised during nimble script execution
I fixed the error by changiing the type of the argument arg in onWifiDisconnect and ipReceivedHandler from pointer to cstring. Now I am able to run nimble esp_compile.
However, I now encounter a new issue when running nimble esp_build --clean-dir --esp-idf-version=V5.0 where ninja stops the build right at the end (842/895). I don't know what could be the cause but it may be related to me using esp-idf 5.0 and using the wrong commands. I know my esp-idf works because I used it to flash the hello world example on my esp32...
Hello,
Now that I am up and running, I was planning to do a simple test with an i2c accelerometer. However, there does not seem to be a library for the MPU6050 written in Nim (not surprising).
However, I know it's possible to import C into Nim with pragmas, futhark or c2nim. I saw you used {.import.} to import c functions and constants to Nesper and I was wondering how you would do it for a sensor library. I'm guessing there may be issues with the fact that it is an I2C sensor ? If I can manage to make the MPU6050 work in Nim using a C or CPP library would be absolutely amazing!