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

Can you switch the codes from ESP-IDF to ESP32 libraries in Arduino IDE? #29

Closed
Paryavi opened this issue Sep 8, 2021 · 105 comments
Closed
Assignees
Labels
feature New functionality

Comments

@Paryavi
Copy link

Paryavi commented Sep 8, 2021

Hi There,

Thank you so much for your codes for ESP32 MCU in ESP-IDF, I have lots of ESP camera boards and a Hologram Nova that has Sara-R410 and I want to connect ESP32 to it.
But the problem is all of my previous application codings are in Arduino IDE as most ESP32 codes are written in Arduino IDE!
So would you please modify your code so that we be able to use ubxlib library in Arduino IDE platform instead of IDF, like what Sparkfun people did?

Thank you so much!

@RobMeades
Copy link
Contributor

Hi there, and thanks for you interest. We've never looked at the ESP32 Arduino IDE, it might not be an easy thing to do. I'll have a look at it tomorrow and comment again here.

@RobMeades RobMeades self-assigned this Sep 8, 2021
@Paryavi
Copy link
Author

Paryavi commented Sep 8, 2021

Thanks, Rob for the quick response, if you look at something like Sparkfun LTE libs that would be great too;
https://github.com/sparkfun/SparkFun_LTE_Shield_Arduino_Library
https://learn.sparkfun.com/tutorials/lte-cat-m1nb-iot-shield-hookup-guide/all

Details:
My project has some image classification with ESP32, take pictures, and send it with LTE (I am familiar with Python not much C++, but working on it!), I was able to send images with Pycom Gpy recently, using micropython!

Gpy is ESP32 plus Sequans Monarch, but they do not have good library support as you do, so that is why we switched to SaraR410M-2B and we wanna integrate it with our ESP custom-designed board. So I recently bought some Sparkfun level-shifters to connect ESP32 3.3 volts to Sara modem 1.8 V Uart pins, similar to Sparkfun Arduino shield Eagle design, but I need codes to send a message(eventually image) from ESP to our website using Sara cellular modem, unfortunately, ESP-IDF is not that optimal, however, I am looking at some easier ways like using Visual studio IDE for IDF integration now, but if you could migrate to Arduino Libs, that would be gold!

Thanks,
MoZen

@RobMeades
Copy link
Contributor

RobMeades commented Sep 9, 2021

Hi again. I started writing a comment about how I didn't understand the relationship between Arduino and ESP-IDF but then I found this article which suggests that ESP-IDF is already there, inside the pre-built libraries included with the Arduino IDE. In other words, you should be able to take the ubxlib code plus the existing esp-idf platform port for ubxlib and simply persuade the Arduino IDE to build and link them against the pre-built ESP-IDF libraries it already has.

Then you would have the ubxlib APIs as well as the Arduino APIs, though of course you should probably NOT use the Arduino serial or GPIO APIs as ubxlib will be using that HW via the ESP-IDF APIs.

Have you tried doing anything like this?

@RobMeades RobMeades added the feature New functionality label Sep 9, 2021
@Paryavi
Copy link
Author

Paryavi commented Sep 10, 2021

Hi Rob,

Thank you, I looked at my Arduino lib folder, I found IDF-related files, so the integration sounds cool!
Yes, I assume you mean ESP is using UART0 with Arduino IDE and ubxlib uses UART0 with Sara modem too which might cause problems.

I used Sparkfun Sara-r4 shield eagle files and added your LTE modem schematic to our ESP integration board in Eagle but I am worried on software side; It is a little vague how to use ESP-IDF ubxlib APIs for me (I worked with ESP-IDF previously, I need to install it again), For example, which ESP32 pins to connect to Sara-R4? I assume Uart0 to UART pins of Sara-r4 using a level shifter... I have components, but honestly, I could not understand how your cellular example work, what should we set when uploading the code, where to add APN? what your example will print in the terminal of ESP-IDF?

My goal (and I assume every developer's first goal) is to send a "Hello World" message using Sara LTE with ESP-IDF, how can I do that with ubxlib Github examples with ESP32? Then I will modify that to send my images...

Some LTE messaging examples;
GPY messaging example: https://docs.pycom.io/tutorials/networks/lte/
Sparkfun: https://learn.sparkfun.com/tutorials/lte-cat-m1nb-iot-shield-hookup-guide/all#example-2-send-a-hologram-message
Hologram: https://www.hologram.io/references/python-sdk

I know you guys are busy but if one of your engineers could add an LTE messaging Github example or record a video on how to use ubxlib/GPIO APIs with ESP-IDF on your ublox1 YouTube channel that would be great.

Thanks,
MoZen

@RobMeades
Copy link
Contributor

Having checked other priorities we will be able to make time to have a poke at this in the next few weeks. I can't promise that it will work, there might be impossibilities or too-hard-for-us-to-solve things hiding within it but I'm hoping this will be just another set of build metadata, no code required. If that is true it will indeed be a valuable addition.

I will report back.

@Paryavi
Copy link
Author

Paryavi commented Sep 11, 2021

Sounds good, Rob, really appreciate it! Also, adding more info on how to use the current cellular API examples will help too, I will dig more on cellular documentation too!

@RobMeades
Copy link
Contributor

On the issue of documenting how to use the cellular API examples, can you provide some hints as to what needs to be clarified? Since we know how to use it and have made an attempt to explain we need your help to figure out where we can improve.

@Paryavi
Copy link
Author

Paryavi commented Sep 13, 2021

Sure, I think first I need to install IDF and run it asap to get a better user experience, However, today I checked the runner folder, it gave more clues on how it might work;
https://github.com/u-blox/ubxlib/tree/master/port/platform/esp-idf/mcu/esp32/runner

It looks like you made some "general" examples here; https://github.com/u-blox/ubxlib/tree/master/example
Where users can access them for all boards, previously I was looking for a cellular example in your ESP-IDF folder!

Also, the hardware part is not clear, if there was a schematic picture (fritzing, or eagle) that would help a lot;
something like Sparkfun schematics; https://www.sparkfun.com/products/14997
My question is which esp32 and sarar410-2B UART ports are connected, or how do they do Uart handshake.

Thanks

@RobMeades
Copy link
Contributor

Hi again. We have implemented Arduino support and have pushed a preview branch here, see the port/platform/arduino directory for more information. This is for you to have a look at, maybe try out, see if it is what you are after. Note that it is (a) still subject to change (it has not been reviewed internally yet) and (b) this preview branch will be DELETED when the feature is merged into master.

On the documentation, what would usually happen concerning hardware is that you would consult the u-blox integration manual for your chosen module and go from there. I will see if we can provide some form of "HW hints and tips" README.md in ubxlib which might point you in the right direction.

@Paryavi
Copy link
Author

Paryavi commented Sep 23, 2021

Hi Rob!

Thank you so much for the great explanation. I was able to copy the files using your Python code in the Arduino Library folder and build the ubxlib src folder, then include and compile a sketch in Arduino IDE successfully, more details after my question. Now I want to write the sketch code there...

My question:

  1. I am not sure where to find these API functions: xxxInit() ,xxxAdd(), xxxConnect().

  2. Assuming my first goal is to send an SMS like this code from Sparkfun (my end goal is to send the camera board picture);
    https://github.com/sparkfun/SparkFun_LTE_Shield_Arduino_Library/blob/master/examples/01_SMS_Send/01_SMS_Send.ino
    In the u_blox repo, which example should I look at?

There are two cell resources in ubxlib;
Cell API:https://github.com/u-blox/ubxlib/tree/preview_feature_arduino/cell
And
https://github.com/u-blox/ubxlib/tree/preview_feature_arduino/example/cell/lte_cfg

My Updates;
I am connecting 4 UART wires; from ESPCAM RX, TX, VCC, and Ground, to Sparkfun Arduino Shield I received yesterday; https://learn.sparkfun.com/tutorials/lte-cat-m1nb-iot-shield-hookup-guide/all

Things I need to do;

  • configuring the pins for ESPCAM in u_cfg_app_platform_specific.h

  • Need to install ESP-IDF and look at how to integrate it with Arduino from the medium article you shared again

  • Then, if it works, we can integrate u-blox SaraR410M-02B-01 to our boards using Eagle.

Thanks,
MoZen

@RobMeades
Copy link
Contributor

RobMeades commented Sep 23, 2021

That's great progress, thanks for looking at the preview branch. If you were able to include and compile/link the ubxlib Arduino library for ESP32 then you must already have the ESP-IDF stuff inside your Arduino environment - maybe ESP-IDF comes with Arduino by default anyway? I only followed the instructions on the Espressif site because that seemed the obvious route, since I don't really know very much about Arduino and I do know about Espressif.

On the examples, the cell examples are just a few small cellular examples, we try to direct you away from those towards the general examples which use the common APIs. The common APIs will work across our cellular and Wifi/BLE modules and are intended to be simpler to use so it is much better to start there, only go down to the cellular API if you need something slightly special.

So, if you want to open a socket to a server, look at the sockets examples, if you want to use MQTT look at the mqtt_client examples, if you want to do location stuff look at the location examples, etc. These examples each include all of the xxxInit() and xxxAdd() functions you need so you should be able to understand what's going on from there.

You mention SMS above: is that a requirement? I imagine you aren't going to send a picture over SMS? If it is a requirement then we will need to add SMS support on cellular (not something anyone has asked us for yet). Not a huge issue, it is on the TODO list, just needs to be moved up.

@Paryavi
Copy link
Author

Paryavi commented Sep 23, 2021

Aloha and Thanks, Rob, I will check the TCP example, that's what I want.

Oh, I thought you mean installing esp-idf independently, I did that previously not sure if I deleted it...
But yes, I have esp stuff installed inside Arduino following the espressif link long ago (esp support inside Arduino you shared).

My goal is to send ESPCAM pictures using sockets, so I was thinking at SMS as a starting point that I know hardware works!, but thinking about it again... more relevant thing I see in Gpy or OpenMV codes as the first step is getting a website IP address using TCP (like Google!).
Check GPu example at bottom of this page;
https://docs.pycom.io/firmwareapi/micropython/usocket/
To send a picture I used this code first to know cellular module, antenna, hologram Simcard,... works(Sequans module inside Gpy);
socket.getaddrinfo()
So putting get address info from TCP work in Arduino(which is essentially C or C++) is a great TODO thing I think for many users, including me! Thanks!

So if you write a code that gets an IP address using TCP in Arduino using the ubxlib lib we have, that is great!
Arduino coding is mostly the same. I will check the TCP example you shared too. I have direct access to WiFi from ESP, we do not use GPS and BLuthotth now, first priority is making sarar4 work using my Sparkfun sarar4 breakout board using ESPCAM(wanted to share a picture of my espcam and sparkfun on my table now but probably sending picture is not supported in Github!

Thanks,
Mohsen

@RobMeades
Copy link
Contributor

RobMeades commented Sep 23, 2021

Sounds like you're having fun! For TCP sockets (assuming ignoring TLS security for now) this is the example you want. The entry point, I suppose the start of setup() in your terms, is this line, then you have to fit the following calls however you would like into the Arduino setup()/loop() world. I'd guess that up to this line you'd probably put in setup(), then you have to decide whether you want bringing the network up (i.e. registering with the cellular network and gaining an IP address) to be part of setup() or you might prefer to put that whole section (i.e. all of lines 212 to 281) in loop(), it entirely depends on how you would like your application to behave; does it connect to the network once, in setup() and stay on forever or does it connect only while it is in loop() and disconnect when it leaves loop()? Only you can decide :-).

I've never used socket.getaddrinfo() in Python, and you need to remember that, despite C being there, hiding, underneath Python, Python is almost the exact opposite of C in almost every way, but it looks like all it effectively does is return the IP address of the device, which you could get, in the context of that example, by calling uCellNetGetIpAddressStr() with the network handle after you've done uNetworkUp(), so something like:

uCellNetGetIpAddressStr(networkHandle, buffer);

...just re-using the buffer that is already there as it is big enough (it just happens to be U_CELL_NET_IP_ADDRESS_SIZE (i.e. 64) characters). The IP address is just a string in the buffer, so if you like you could print it with:

uPortLog("The IP address of this device is %s\n", buffer);

The thing to remember with the ubxlib C code is that everything is done using handles and all of the sockets stuff is pure BSD sockets, there should be no surprises to a BSD sockets user (which is pretty much all sockets users I think).

Looking forward to seeing a picture of your ESPCAM :-).

@Paryavi
Copy link
Author

Paryavi commented Sep 24, 2021

Good morning Rob!

Thanks for your patience, I know it's hard dealing with non-computer engineers, it took me a while as an electronics engineer to learn Python from Coursera (I knew C to some extent). Anyways, I tried copying the parts you mentioned in Arduino and call the functions, I got this error; exit status 1, 'networkHandle' was not declared in this scope
I was not sure what to include and what to ignore at the beginning of the sketch based on the codes...
I think if you write a sample .ino file in your arduino sketch example folder, that is great.

Here are two examples I was talking about, tested in OpenMV which I found useful for wireless projects (fetching IP address of a website and photo upload);
https://github.com/openmv/openmv/blob/master/scripts/examples/OpenMV/14-WiFi-Shield/http_client.py
https://github.com/openmv/openmv/blob/master/scripts/examples/OpenMV/14-WiFi-Shield/http_post.py

Ok, since you said you know IDF more, I will start with it to make sure the sarar4 hardware is working, then I will go back to Arduino for the photo upload project. I have the ESPCAM photo upload code in Arduino already.

Ok I installed ESP-IDF again, and I went to configure these files (pins for ESPCAM);
https://github.com/u-blox/ubxlib/tree/master/port/platform/esp-idf/mcu/esp32/cfg
I think you mentioned, u_cfg_app_platform_specific.h should be modified more based on ESP format which in my case is ESPCAM(ESP32S), there were many RX and TX to be set! so I panicked a bit, btw what is the short-range module?

It looks like I should change most of them to -1 as they are not connected to sara r4, I am trying to mimic Sparkfun shield wiring, they just connect rx and tx, and I will just connect rx,tx,vcc,gnd from espcam to sparkfun.
4 pins in ESPCAM UART are shown here; https://randomnerdtutorials.com/program-upload-code-esp32-cam/

In Sparkfun SaraR4 shield, they mention they connect all uart handshake signals to ground as recommended for a UART "with NO FLOW CONTROL" mentioned at the lower part of page two of their schematic; https://cdn.sparkfun.com/assets/3/9/d/5/f/lte_cat_m1_shield_schematic.pdf
I assume I should do the same.

Hopefully, when I am able to run Sarar4 with ESPCAM, I will definitely send its success picture, haha!

Thanks,
MoZen

@RobMeades
Copy link
Contributor

Understood, in that case I will see if I can write an Arduino example, making some assumptions about how the application should behave, which does the same send/receive to a TCP echo server as the sockets example.

On the setting of pins etc., yes, you either edit the u_cfg_app_platform_specific.h under the ESP-IDF folder ('cos that's the chipset you're building for) or you override the values, or just set them, in the application itself, it is entirely up to you. All of the pins that might be required are present in the file; you might be using one of our Wi-Fi/BLE modules or GNSS modules etc., we can't know. But if you're only using a cellular module you only need to set the things with "CELL" in the name and if you're not using flow control you should set the CTS/RTS ones to -1 since they are not connected.

I won't close this issue until I've seen the picture :-).

@u-blox u-blox deleted a comment from Paryavi Sep 29, 2021
@u-blox u-blox deleted a comment from Paryavi Sep 29, 2021
@u-blox u-blox deleted a comment from Paryavi Sep 29, 2021
@RobMeades
Copy link
Contributor

Hi again: I have pushed an updated version of the Arduino preview branch, called preview_feature_arduino_updated (the previous preview branch is still there, unchanged, in case you need to refer to it for some reason).

Please delete any stuff that was created last time by running the Python script, read the revised README.md (some of the script names and certainly the script behaviours have changed). The most important thing about this update is that it includes an example sketch, an Arduino version of the sockets example.

This branch has also passed testing on our test system and so is likely quite close to the version I will merge. When I have merged Arduino support into master I will delete both of these preview branches.

@Paryavi
Copy link
Author

Paryavi commented Sep 29, 2021

Hi Rob, it is awesome to test the socket example in Arduino, I deleted my previous libraries to try the preview version.

However, I get the following error when trying to run u_arduino.py;
No such file or directory: 'source_lib.txt'

I guess it is because in the code you have added;
UBXLIB_LIB_POSTFIX = "_lib"

Source file listing file

SOURCE_FILES = "source" + UBXLIB_LIB_POSTFIX + ".txt"

But there is no "source_lib.txt" file in your Arduino folder...

@Paryavi
Copy link
Author

Paryavi commented Sep 29, 2021

Comparing to the previous Arduino preview folder; https://github.com/u-blox/ubxlib/tree/preview_feature_arduino/port/platform/arduino

It looks like you probably forgot to add these files in the new Arduino preview folder; source_lib.txt and include_lib.txt, so I will just copy those from the previous preview and hopefully it will work!

@RobMeades
Copy link
Contributor

Sorry, my fault, I was testing with the automated test system which always specifies the names of those text files on the command-line to u_arduino.py rather than using the default names; it's just the name in u_arduino.py that is wrong, UBXLIB_LIB_POSTFIX should be "" not _"lib". Don't use the old files, the contents are different and it probably won't compile.

I have update the branch so that UBXLIB_LIB_POSTFIX is now correct.

@Paryavi
Copy link
Author

Paryavi commented Sep 29, 2021

No problem my friend,
Yeah, it was not compiling, but it successfully copied the ublox in the Arduino Library using old files...
Anyways, I will delete them and use your updated version now, thanks for the quick reply.
Btw, I am curious how you test the code, what hardware do you use? Probably Nina...

@RobMeades
Copy link
Contributor

We test ubxlib in general on the things listed here, where the Arduino ones are instances 11.1 and 22, so an ESP32-DevkitC and a NINA-W10.

@Paryavi
Copy link
Author

Paryavi commented Sep 29, 2021

Thanks.

I get the following error compiling empty sketch example in Arduino IDE;

Library ubxlib has been declared precompiled:
Precompiled library in "C:\Users\myuser\Documents\Arduino\libraries\ubxlib\src\esp32" not found
C:\Users\myuser\Documents\Arduino\libraries\ubxlib\src\u_port_uart.c: In function 'uPortUartOpen':
C:\Users\myuser\Documents\Arduino\libraries\ubxlib\src\u_port_uart.c:275:19: error: 'uart_config_t {aka struct }' has no member named 'source_clk'
config.source_clk = UART_SCLK_REF_TICK;
^
C:\Users\myuser\Documents\Arduino\libraries\ubxlib\src\u_port_uart.c:275:33: error: 'UART_SCLK_REF_TICK' undeclared (first use in this function)
config.source_clk = UART_SCLK_REF_TICK;
^
C:\Users\myuser\Documents\Arduino\libraries\ubxlib\src\u_port_uart.c:275:33: note: each undeclared identifier is reported only once for each function it appears in
exit status 1
Error compiling for board Adafruit ESP32 Feather.

@RobMeades
Copy link
Contributor

That's strange: it looks like the version of the underlying ESP-IDF code is different in your case, their definition of uart_config_t has changed. Do you know what ESP-IDF version you have?

@Paryavi
Copy link
Author

Paryavi commented Sep 29, 2021

idf4.2_py3.8_env but I can install a version that worked for you...

@RobMeades
Copy link
Contributor

All I did was follow Espressif's instructions; it compiled for you yesterday and none of that code has changed. Don't understand what's different.

@Paryavi
Copy link
Author

Paryavi commented Feb 15, 2022

Oh, actually, I did not know I can remove the 16 clippers from the package!
I thought these two extra black boxes are clamps for holding the harness wires!
Also, the startup guide does not talk about it assuming everyone is smart, haha!
https://support.saleae.com/getting-started/setup
Saleaeeee

@RobMeades
Copy link
Contributor

Oooo, weird: mine came in a little plastic bag, which is a tad more obvious!

@Paryavi
Copy link
Author

Paryavi commented Feb 15, 2022

Hi Rob,

I hope all is well and thanks for inspiring me to search for and find the Saleae clips!
My goal is to have Module Power_ON(looking at 1.6.1 on integration Manual).
TowardsModule ON

I set Saleae to record when it sees a rising age trigger on GPIO0_LTE_START MCU signal applied to the Gate of an NMOS that when is high it will conduct hence provides Low_level on PWR_ON pin(all transistors are NMOS).
Only the cell_enable_power signal goes to a PMOS and it will be active when the gate is Zero volts, in that case, it will conduct 3.3V to VCC pin.

I am following your suggestion for having RXD as close to the module as possible but for now, I was curious to see what MCU is sending on the Gates.
My question is, I do not understand why U_cell_enable_power(channel zero) toggles! is it because I pressed the Reset button? I think MCU should always provide zero volts on this pin(GPIO19 of MCU which is LTE_START_NOT), similar to Fig.9 of the manual PDF where there is a stable VCC and Power_ON signal toggle to a LOW_Pulse to turn the module ON.
In Channel D0 we see Low on both ends of the signal; which provides a stable Low voltage on the gate of PMOS which is good which keeps providing VCC to the module, but channel D0 shows that, at the crucial important time when Power_ON is Low_Level, we see Gate of PMOS jumps to High so actually in that toggle time, the PMOS transistor is OFF, so module does not get any VCC during that time. and UBLOX RXD when it does not receive VCC is sending a Pulse on D4!
Our flags are:
U_CELL_ENABLE_POWER_PIN_INVERTED
-DU_CFG_APP_PIN_CELL_ENABLE_POWER=19
Sara_R4_CRB

Thanks,
Mohsen

@Paryavi
Copy link
Author

Paryavi commented Feb 15, 2022

Since I assume the previous message signals were probably when I hit our reset button on the board, now I just connected the Lipo battery to the board and looked for trigger on Power_ON without pressing any button, it resulted in the following signals;
Also, like previous message, I have connected Ground of Saleae to the ground of the HDMI programmer (I use it to load CLI code from PC) and D3 signal which goes to GPIO3/RX MCU(comes from RXD from level shifter) is connected to HDMI programmer RX pin, that is probably why we see a high signal there(I guess I should detach signals from HDMI for now!).
Battery_ON

@RobMeades
Copy link
Contributor

I think we need to zoom out a little here: there is nothing in the ubxlib code that operates on the micro-second timeframe. The RTOS tick on Arduino is 1 ms, nothing software-driven is going to happen faster than that, and very likely 10 times slower than that.

For instance, for the UART data lines, running at 115,200 and driven by the UART HW block (not SW), one bit is 8 us, one byte is 80 us (1 start bit, 8 data bits, 1 stop bit), so we need to be looking here at many 100's of ms to see what's going on in SW terms. Anything less than that is HW which I can't really be of much help with!

@RobMeades
Copy link
Contributor

RobMeades commented Feb 15, 2022

Can you attach a probe to the TXD line as well as the RXD line (TXD from the MCU is what you will see before anything else), in the Saleae PC SW attach a serial analyzer to both of the data lines displaying both ASCII and hex (@115200), then do another trace with a timespan of 15 seconds (yes, I do mean seconds!) from power-on and post the fully zoomed-out view first?

@Paryavi
Copy link
Author

Paryavi commented Feb 16, 2022

Aloha Rob, I have two 15 seconds traces; When everything is Off and I insert the Lipo battery to energize the MCU.
Also when Lipo is there and I hit the Reset button connected to EN of MCU.

  1. Inserting Lipo:
  • D0 channel: On second 6.5: GPIO19 connected to the gate of PMOS goes Low, hence 3.3V goes to SARA VCC pin.
  • D1 shows: at 6.7 sec, MCU GPIO0 applies high voltage to NMOS Q6 Gate, so SARA Power_ON pin should see toggle from 1 to zero (If there was 1.8V pull-up internal there).
  • D6: MCU TX output(AT command signals?)

WhenLipo_connect
2. Lipo was connected so MCU is ON, I started recording with Saleae, then I hit the Reset button on the board; kinda same thing happens;
When Hit Reset button

I use level shifter transistors in our design to shift 3.3 to 1.8V (same as Sparkfun level shifter you use; https://www.sparkfun.com/products/12009). Our Level_shifter Gates are energized with V_int:1.8V, I guess since I do not have 1.8V when measuring V_int signal with a multimeter, TX handshake from MCU can not be converted to 1.8V equivalent and reach TXD on SARA (level shifter transistors are OFF as their Gate is connected to V_int).
Thanks

@RobMeades
Copy link
Contributor

RobMeades commented Feb 16, 2022

Great, so those traces all look sensible: the Enable Power line is being brought up, the TXD line is the MCU sending "AT" to see if the module is awake, the PWR_ON line is being toggled by the MCU to power the module on and then to power it off again at the end when it fails to respond.

Can we now add two more probes: one connected to the 3V3 power supply pin of the module and another connected to the V_INT output from the module, both as near to the module as possible, and take another trace? Let's make it 10 seconds this time.

@Paryavi
Copy link
Author

Paryavi commented Feb 16, 2022

Thanks for interpreting the results, before adding more probes, with your explanation I might know what is wrong; Enable Power is not inverted here;

At second 2: You say; the Enable Power line is being brought up;
Actually, As I mentioned we only have one PMOS transistor in our design, Q5 (and on D0 Saleae we are looking at its Gate! signal coming from MCU GPIO19);
#29 (comment)
I know PMOS looks different, in conventional NMOS, as you know, when we apply High on Gate, it will switch(source to drain), in PMOS it is the opposite, when we have Low on Gate, it will switch(here in Eagle schematic, when it sees Low on its gate, it will switch 3.3V to VDD which is Sara VCC). So in order to Enable power to SARA, we need to have the opposite waveform. right?

I think that is why you were suspicious of 3.3 V and want me to add probes there, I will do shortly.
Thanks for helping me debug!

@RobMeades
Copy link
Contributor

Ummm, could be, I'm not really a HW guy I'm afraid, you know best!

@Paryavi
Copy link
Author

Paryavi commented Feb 16, 2022

Adding VDD Probe
Yeah, I added Saleae Probe D7 is VDD, Drain of Q5, which goes to SARA as VCC (after it has seen Q5 PMOS), and is an inversion of what we want(D0, Cell_enable power).
Btw, sorry it is not clean VDD or VCC I will work on that.

So it sounds like Salea Probe D0; -DU_CELL_ENABLE_POWER_PIN_INVERTED is not an inversion signal on the MCU side(-DU_CFG_APP_PIN_CELL_ENABLE_POWER=19) as we require it to, right?

@RobMeades
Copy link
Contributor

Well U_CELL_ENABLE_POWER_PIN_INVERTED is definitely the correct #define and you have corrected the spelling and, I guess, done a clean build; please do so if you haven't; remember that changing a #define passed to the compiler on the command-line hasn't changed the code so no "make" process will know to re-build the files in question.

@Paryavi
Copy link
Author

Paryavi commented Feb 16, 2022

Ok, I just rechecked the spelling, it is fine;

arduino-cli compile --fqbn esp32:esp32:esp32 --clean -v -u -p COM3 --libraries . --build-property compiler.c.extra_flags="-DU_CELL_PWR_ON_PIN_INVERTED -DU_CELL_ENABLE_POWER_PIN_INVERTED -DU_CELL_RESET_PIN_INVERTED -DU_CFG_TEST_CELL_MODULE_TYPE=U_CELL_MODULE_TYPE_SARA_R410M_02B -DU_CFG_APP_PIN_CELL_ENABLE_POWER=19 -DU_CFG_APP_PIN_CELL_PWR_ON=0 -DU_CFG_APP_PIN_CELL_RESET=2 -DU_CFG_APP_PIN_CELL_TXD=1 -DU_CFG_APP_PIN_CELL_RXD=3" --build-property compiler.cpp.extra_flags="-DU_CELL_PWR_ON_PIN_INVERTED -DU_CELL_ENABLE_POWER_PIN_INVERTED -DU_CELL_RESET_PIN_INVERTED -DU_CFG_TEST_CELL_MODULE_TYPE=U_CELL_MODULE_TYPE_SARA_R410M_02B -DU_CFG_APP_PIN_CELL_ENABLE_POWER=19 -DU_CFG_APP_PIN_CELL_PWR_ON=0 -DU_CFG_APP_PIN_CELL_RESET=2 -DU_CFG_APP_PIN_CELL_TXD=1 -DU_CFG_APP_PIN_CELL_RXD=3" ubxlib\examples\sockets\sockets.ino

I recompiled it from the Arduino command-line interface to the board, the same issue exists.
remember that changing a #define passed to the compiler on the command-line hasn't changed the code so no "make" process will know to re-build the files in question.
So what do you recommend we do to change the code and make it re-build? I guess I should look at cli documentation. (We already have passed --clean that cleans up the build folder and does not use any cached build, I also run arduino-cli cache clean to command line before compiling).

I add the #define U_CELL_ENABLE_POWER_PIN_INVERTED to the header section in the sockets.ino code, it did not help.

@RobMeades
Copy link
Contributor

Delete the build directory is the usual way, then you can see that all the object files have gone.

@RobMeades
Copy link
Contributor

RobMeades commented Feb 17, 2022

Just to be completely sure, you do have these lines in cell.h, i.e. as the master version here?

image

@Paryavi
Copy link
Author

Paryavi commented Feb 17, 2022

Yes, I was looking at them just now, also I am deleting the temp folder content now...
C:\Temp\arduino-sketch-...

@RobMeades
Copy link
Contributor

RobMeades commented Feb 17, 2022

In every example and every test, when the cellular instance is created, it prints out what the "on" state of the Enable Power pin is (you've quoted such text above), so you could re-check that.

@Paryavi
Copy link
Author

Paryavi commented Feb 17, 2022

Not sure where can I check the print of cellular instance(uCellDeinit())? Normally I use Serial.print() and read the serial monitor.
Btw, in Arduino IDE, Can I add #define U_CELL_ENABLE_POWER_PIN_ON_STATE 1?

@RobMeades
Copy link
Contributor

RobMeades commented Feb 17, 2022

Not sure I understand: can you not just look at the debug serial port output of the ESP32 chip? It's just as you have already quoted above ("U_CELL: initialising with enable power pin 19 (0x13) (where 0 is on)...").

@Paryavi
Copy link
Author

Paryavi commented Feb 17, 2022

You are right, previously when I was uploading code to feather board using USB cable in the Arduino serial monitor I would see more data; #29 (comment)

Currently, I only see ATATAT... using FTDI programmer connected to the board. I am not sure if FTDI caused it or I need to modify some parameters. I will search for the ESP32 chip debugging tools, looks like Arduino CLI has a debugging tool...
AT

@Paryavi Paryavi closed this as completed Feb 17, 2022
@Paryavi Paryavi reopened this Feb 17, 2022
@Paryavi
Copy link
Author

Paryavi commented Feb 17, 2022

Hi Rob, Platform IO has a great debugging environment, it supports Arduino and esp32, I was able to almost build ublox sockets example there, I get one error referring to u_cfg_os_platform_specific.h lines 97; 'CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT' undeclared (first use in this function)

@RobMeades
Copy link
Contributor

RobMeades commented Feb 17, 2022

Are you sure you are connected to the correct COM port of the FTDI chip on the board? What you're showing there looks like the port that is connected to the cellular module rather than the trace UART. When you boot the ESP32 chip I would expect to see a splurge of its boot output, e.g.

boot: ESP-IDF v5.0-dev-1554-g20847eeb96 2nd stage bootloader
boot: compile time 23:14:24
boot: chip revision: 1
boot_comm: chip revision: 1, min. bootloader chip revision: 0
boot.esp32: SPI Speed      : 40MHz
boot.esp32: SPI Mode       : DIO
boot.esp32: SPI Flash Size : 2MB
boot: Enabling RNG early entropy source...
boot: Partition Table:
boot: ## Label            Usage          Type ST Offset   Length
boot:  0 nvs              WiFi data        01 02 00009000 00006000
boot:  1 phy_init         RF data          01 01 0000f000 00001000
boot:  2 factory          factory app      00 00 00010000 00100000
...

Do you see that in your trace output?

As to the Platform IO thingy, looks like they are using a different version of ESP-IDF, I have a feeling that ESP-IDF changed their #defines for things at some point. Looks like it's become CONFIG_PTHREAD_TASK_PRIO_DEFAULT instead of CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT and, in the sdkconfig,h shipped with whatever version of ESP-IDF Platform IO uses, they've removed the backwards-compatibility entry that defined CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT to be CONFIG_PTHREAD_TASK_PRIO_DEFAULT.

For now you can just change CONFIG_ESP_PTHREAD_TASK_PRIO_DEFAULT to CONFIG_PTHREAD_TASK_PRIO_DEFAULT in the u_cfg_os_platform_specific.h for the ESP-IDF platform and I will make that change here also, might as well.

@Paryavi
Copy link
Author

Paryavi commented Feb 18, 2022

What you're showing there looks like the port that is connected to the cellular module rather than the trace UART.
Thanks, Rob, I will modify the Platform IO as you suggested, btw you are right! between RX and TX pins of MCU and Module we have an FTDI program port to program the MCU, we did so since we needed many pins of ESP32 for driving the camera so we wanted to conserve some GPIOs. So the ATATAT commands I was seeing in Serial Plotter of IDE were coming from MCU after being programmed!
To access the state of the Enable Power pin, today I uploaded the same code on my feather board connected to a Ublox shield I designed for OpenMV, where RX and TX are connected to Module and the board is programmed and debugged using a micro-USB port. It shows, the enable-power pin from MCU that goes to the gate of PMOS is inverting (after 4 seconds it sends Zero to the gate of PMOS hence energizing the module);
"U_CELL: initialising with enable power pin 32 (0x20) (where 0 is on)"
The interesting thing is it will U_CELL_PWR: powering on after 4 or 5 seconds;
Cell_Enable_Power_timing
We also see the boot splurge data at the top section of the screenshot.

So we see the inversion signal from MCU 4 or 5 seconds after the MCU Reset button is pushed;
Cell_Enable_Power

So actually we were wrong thinking AT commands last shortly(a few seconds between two Power_ON pulse signals).
So the MCU energizes the module after five seconds when it prints: "U_CELL_PWR: powering on" and sends AT commands for almost one minute. Therefore I am not sure what is the first Power_ON pulse(right after Reset) is for as seen in the Probe after Resetting the MCU.
Hopefully, we will be able to turn this module ON soon and use it for our prototype, then we can extend it for many of our insect traps...

@RobMeades
Copy link
Contributor

OK: it might put a bit of a crimp in your development, not being able to see any debug output from the MCU on your actual target, but that's your choice of course.

As to that initial pulse over on the left, I guess that's simply due to the default state of a pin 19 for ESP32. The first thing the code does when it initialises the cellular instance is to put all of the IO lines in the correct default statues. For the Enable Power pin, with the inversion in place, the code would set its default state to high, so that it can be set low to do the Enable Power part. So I assume all your seeing there is that the ESP32, at boot, has pin 19 low, then when the code starts running it sets pin 19 high as the requested default state (i.e. "off"). It's a transitory state.

@Paryavi
Copy link
Author

Paryavi commented Feb 18, 2022

Thanks, Rob,
I wrote a simple code to try to turn the module ON, In this code I assume when I only apply 3.3V on the VCC pins of the module, then its pin 15, PWR_ON should be pulled up to 1.8V, but it does not. So toggling the Power_ON gate is futile as its drain(module PWR_ON pin) is always zero, so I guess we need to solder a new board!

  • So I uploaded the code to my target module(CRBCAM) and since pin 15 is not pulling up when I have VCC energizing the module, nothing happens.

  • When I apply a Low signal from MCU to Q5 PMOS gate, the Drain of it goes from 1.89V to 3.3Vs. I am not sure if it is a rising edge on VCC as the datasheet requires for switch_on sequence(but I know it is not that important as when there is VCC, ).The code just energizes the module for 39 seconds and applies a Low pulse on the Power_ON drain twice(2 secs after cell enable sends VCC to the module and 30 secs later.)

In contrast, when I upload the simple code to another SARA module(the cellular shield we designed for OPENMV), I have a stable 1.53V pulled up signal on PWR_ON and 2.7V on RESET_N pins. When the code applies a Low pulse for a valid duration on the PWR_ON pin, it causes the V_INT to go to 2.19 Volts but V_INT goes back to zero afterward.

//#define CELL_ENABLE_POWER 19
#ifndef LTE_ON_NOT
#define LTE_ON_NOT 19
#endif
//#define PWR_ON 0
#ifndef LTE_START
#define LTE_START 0
#endif

const int CELL_ENABLE_POWER = LTE_ON_NOT;
const int PWR_ON_GATE = LTE_START;

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
pinMode(PWR_ON_GATE, OUTPUT);
pinMode(CELL_ENABLE_POWER, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
//first let's wait for a few seconds after Reset
Serial.println("Let's not energize module for 4 sec, VCC OFF");
digitalWrite(CELL_ENABLE_POWER, HIGH);
digitalWrite(PWR_ON_GATE, LOW);
delay(4000);
Serial.println("Let's energizing module for 37sec, with VCC ON ");
digitalWrite(CELL_ENABLE_POWER, LOW);
delay(100);
Serial.println("And Now LOW LEVEL on Pwr_ON Drain to turn module ON");
digitalWrite(PWR_ON_GATE, HIGH);
delay(2500);
digitalWrite(PWR_ON_GATE, LOW);
Serial.println("No Toggle Pwr_ON and trying to energize for 30 sec, here comes AT commands");
delay(30000);
Serial.println("LOW LEVEL on Pwr_ON Drain for 3 secs while having VCC there, trying to energize for 20 more sec");
digitalWrite(PWR_ON_GATE, HIGH);
delay(2500);
digitalWrite(PWR_ON_GATE, LOW);
delay(20000);
Serial.println("Let's repeat the loop");
}

Btw, I see these serial prints as I don't have AT commands in this code!

@RobMeades
Copy link
Contributor

RobMeades commented Feb 19, 2022

I'm not sure I'm really following this but I think you're saying that even with your simple code you can't get the module into a state where the VINT output from the remains high. All I can do is point out the PWR_ON-low pulse timings from the the SARA-R4 series data-sheet:

image

Also, it is worth double-checking that your board can supply both the average and the peak current required by the SARA-R410:

image

@Paryavi
Copy link
Author

Paryavi commented Feb 28, 2022

Hi Rob,

I used a power supply with a 750 mA limitation(500 for SARA and 250mA for ESP32) and 4.2V instead of a battery port, but the board was not pulling up PWR_On when VCC was applied, and it was a soldering issue. We soldered 2 new boards, that pull the PWR_ON pins, one of which is using the SARAR422S module.

With the new SARAR410M board, I can turn the module ON and OFF with my simple code. When the module is ON, I have V_INT and RESET_N pin pulled up internally to1.8V and 0.8V on PWR_ON. I loaded sockets.ino code; I get the following AT commands;

AT
ATE0
AT+CMEE=2 //Report mobile termination error
AT+UDCONF=1,0 // Enables/disables the HEX mode
ATI9
AT&C1
AT&D0
AT+UCGED=5 // Channel and network environment description
AT+CPSMS=0
AT+CPSMS=0
AT+CPSMS=0
AT
AT

The Module Response;
AT
OK
AT
OK
ATE0
OK
OK
OK
L0.0.00.00.05.08,A.02.04
OK
OK
OK
OK
+CME ERROR: SIM failure
+CME ERROR: SIM failure
+CME ERROR: SIM failure
OK

The Simcard section has failed and I do not have Voltage on the VSIM pin. It looks like a few other developers had the same issue; https://portal.u-blox.com/s/question/0D52p00008nvKcnCAE/network-connectivity-issue-with-sara-r410m02b
I am looking for better reflow ovens/stencils...

For SARA-R422M8S module with GPS antenna(a design similar to Figure 68: of international manual);
GPS

It shows 1 Volta periodically on VSIM, I have loaded the sockets code on the GPS board, it just prints ATATAT in the serial monitor, and I get no response from the module, also in contrast to the SARA R410 module, the GNSS module I tested does not turn the VCC OFF. I will use Saleae probe to check the module signals.

I have set # define U_CFG_APP_GNSS_UART 1
I assume we still use UART hardware block 1 in ESP32 for GNSS too, should I use 2?
-DU_CFG_TEST_CELL_MODULE_TYPE=U_CELL_MODULE_TYPE_SARA_R422

In PCB design, we have connected TXD-GNSS pin to ESP32 GPIO 22 so I modified the u-cfg app platform-specific file as follows;

#ifndef U_CFG_APP_PIN_GNSS_TXD
/** The ESP32 GPIO output pin that sends UART data to the GNSS module. */ This comment is ambiguous since the module GNSS_TXD pin is output from the module to ESP32 MCU!
I have set# define U_CFG_APP_PIN_GNSS_TXD 22

For the SARAR422S module, I found the following codes;
https://github.com/u-blox/ubxlib/tree/master/example/location
Which one do you recommend I use?
Probably the following one?
https://github.com/u-blox/ubxlib/blob/master/example/location/main_loc_gnss_cell.c

@Paryavi Paryavi closed this as completed Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality
Projects
None yet
Development

No branches or pull requests

3 participants