Cubecell Software Serial

I’d be interested in the wave form, it should be 104ms square waves per bit. Yes it looks like this isn’t good code for this usecase, and receiving an entire byte with interrupts (in theory) off blocks for ~100us x 21 = 2.1ms which is a very long time for this processor…I will try porting AltSoftSerial that uses timers and blocks per bit instead. Thing that work on 8Mhz 8bit processors don’t directly translate to 32bit 48Mhz ones.

I’m not convinced that noInterrupts() turns off all interrupts either as TX works most of the time but has repeated identical pulses of corrupt data over time.

It’s an odd thing that a higher bps would block for less time individually too, but then timing requires more precision.

Unless Heltec have microsecond timers available for interrupt purposes, I think you are stuck with blocking code.

I spent a few minutes looking at this today. I just wrote an endless loop, setting a pin high, calling a 104uS delay, then setting the pin low, another 104uS delay.
The good news is that the waveform is rock solid, so I think the “noInterrupts()” does work.
The bad news is that the time between transitions is 107.3uS, and that’s without all the other overheads, such as the function for reading the rx pin, the bit count and byte shift etc.
So I reckon the timing is out by too much to work reliably.

It’s one of those times when I would revert to assembler, as It’s hard to count cycles in C.

Thanks @johnarnoldbrown for the feedback.Yes this is much harder and more hacky than I expected, there are so many good reasons this is properly done in hardware.

I have successfully harnessed the PWM1 interrupt but so far failed to stop is firing every ~2uS when it’s active. It’s more precise and possibly enough to use for timing but getting the timing right is hard, and I’ve tried so many times to get more than on/off control of it e.g set it to 104uS. Other SoftSerial implementations pulse a debug pin when they’re reading the input so the timing can be tweaked until they line up correctly, and that sounds like what’s required.

What it really needs is a PSoC creator built timing object just for this but I don’t know if @Aaron can do that. He did comment on the Github issue that he was looking into a SoftwareSerial implementation and I’d be so happy for him to do that :slight_smile:

Hi bwooce I have been using the latest release of softSerial (29/2/20) by Arron and this outputs good clean NMEA sentences. But I can not get the Intergration of TinyGPS as it cant find the maths functions. Any pointers to how you got TinyGPS to work in CubeCell? Manay thanks in advance.

Simon

please try the example in this commit:

this is compiling fine in vscode

I’m using TinyGPS++ and I had to add this to TinyGPS++.cpp:

#define PI           (M_PI)
#define HALF_PI      (M_PI / 2.0)
#define TWO_PI       (M_PI * 2.0)
#define DEG_TO_RAD   (M_PI / 180.0)
#define RAD_TO_DEG   (180.0 / M_PI)

#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x)        ((x)*(x))

I got a linker collision deep in a Cubecell library from memory too, and had to comment out a definition (unused) there.

Hi IT still did not compile for me due to failure of maths functions . Which version of TinyGPS.h did you use as there are several knocking about.
Thanks Simon

Hi @Sivaelid can you give us a pastebin/gist link with a copy&paste of the errors please?

I believe the supplied example from @wasn is using TinyGPS (from library manager?). I was using TinyGPS++ and yes I had to invent the math functions.

Edit: correct person who wrote the example

The tinygps example is for the normal tinygps library installed from the library manager

Hi WASN,bwooce and Arron

Just to Say thanks for your advice. I now have several example sketches working using the softSerial function at 9600 baud with my GPS (Quectel L70, L96) chips. Will now combine with LoRaWAN sketches to act as a High Altitude tracker with Cubecell Board or Module.

The Key for me was the missing Math functions in the .cpp either TinyGPS or TinyGPS++. We really need a CubeCell Maths.h library. I did not go down the vscode route, I assume that must add in maths function at some point. Thought I do use vscode for other projects like the FOSSASAT Groundstation.

Still looking forward to the ASR6502 due to the increase in serial ports but mainly the added Analogue inputs, As in my current project I need to monitor both battery and solar input levels V and A, to allow power optimising and spare energy used to warm units, as they may go to -40C.

Simon

just uploaded an example for using a GPS with the softSerial and LoRaWAN inlcuding TTN Decoder:

This needs the changes from @bwooce mentioned above (adding defines in TinyGPS++.cpp)

I am using this GPS module:

https://de.aliexpress.com/item/32978843367.html?spm=a2g0s.8937460.0.0.78d82e0exdY2Ho

it fits in the sensor side of the CubeCell Capsule

Hi,

Thanks for all the info and the hard work. I am trying to add my GPS neo 6m with the code you provided. but I keep getting this error when compiling :
softSerial.h: No such file or directory…

Sorry I am new at this

J

have you installed the extension for the cubecell with the boardmanager?
if yes please use the github repository.

Yes, all the examples are working except the GPS one because of the softSerial.h:

Ok I manage to resolve the problem by copy paste the mising softserial.

But now when compiling I have the following error. I did make the changes from @bwooce
…Documents\Arduino\libraries\TinysGPSPLus/TinyGPS++.h:27:25: fatal error: application.h: No such file or directory …

just edit the file TinyGPS++.h
and delete the referenced line

I followed all the good advise in this thread, but got stuck very close to success:
Using the “LoRaWan_GPS” example gets me a successful fix of the position at the first run, but for all subsequent loops I’m only seeing the old data again: E.g. latitude and longitude have for all measures that exact same number till 7th or 8th digit. It seems the position is not updated at all. What can I try to fix this?

FYI: If I try “TinyGPS” from the examples library, I can see each second alternating positions and measures on the console. I conclude from this, that my Neo M8N is basically working on the CubeCell.

Maybe it is of interest that the TinyGPS example can be even more simplified by making some changes. The ‘smartDelay(0)’ function call spread into a lot of time consuming functions can then be avoided.

I made the following changes:

char buff[2000];
int buffIndex;

char getch()
{
long startTime;

startTime = millis();
while (true)
{
if (millis() - startTime > 50)
return(’?’); // timeout, char invalid
if (ss.available())
return (ss.read());
}
}

void loop()
{
char c;
buffIndex = 0;

while (true)
{
c = getch();
//Serial.print©;
if (c == ‘?’ && buffIndex > 0) // fix complete?
break; // no more chars for this fix
if (c != ‘?’)
buff[buffIndex++] = c;
delay(0);
}
buff[buffIndex] = ‘\0’; // put an end char
for (int i=0; i < buffIndex; i++)
{
gps.encode(buff[i]);
}
//Serial.print(buff);
delay(0);

It relies on the observation that a GPS module sends a bunch of data when it has got a fix, then is waiting for the next fix. So this time can nicely be used in the program by putting the incoming data into a buffer, calling the tinyGPS++ library and after that doing all the processing or display of the data.
I tested that with a Ublox GPS M6 module.

Nobody interested in this? Could be useful for @wasn in his example.

Achim