system
December 14, 2014, 1:25pm
#1
I’m running a Gps-Shield and Micro Oled. Getting a byte-Buffer the conversion to String failed using (const char*)ByteBuffer*.*
```
*// initializing oled…
oled.setFontType(0);
int inByte = 0;
byte pbyGpsBuffer[100];
int byBufferIndex = 0;
void loop()
{
byte byDataByte;
if (Gps_serial.available())
{
byDataByte = Gps_serial.read();
Serial.write(byDataByte);
pbyGpsBuffer[ byBufferIndex++ ] = byDataByte;
if( byBufferIndex >= 100 )
{
byBufferIndex = 0;
File dataFile = SD.open(“gps.txt”, FILE_WRITE);
// get Byte-Buffer to String
for (int i=0; i<=100; i++) {
str += (const char*)pbyGpsBuffer[i];
}
oled.clear(PAGE);
oled.setCursor(0, 0);
oled.print(str);
oled.display();
}
}*
```
KenF
December 14, 2014, 1:33pm
#2
Fumbling around in the dark, what happens if you remove the word "const" ?
guix
December 14, 2014, 1:48pm
#3
Hello and welcome,
Why use a String? You already have an useable char array.
if( byBufferIndex == 99 )
{
pbyGpsBuffer[ byBufferIndex ] = '\0';
byBufferIndex = 0;
...
oled.print( pbyGpsBuffer );
...
}
system
December 14, 2014, 3:05pm
#4
the matter of conversion is to filter NMEA-data - with strsep() for a convenient output on LCD.
pbyGpsBuffer data:
$GPGSV,3,1,12,01,00,000,,02,00,00
works well,
oled.write(pbyGpsBuffer*);*
but needful are just some tokenized informations, so i do that with strsep() on a String. If there is a direct way with ByteArray.. will be better
system
December 14, 2014, 3:34pm
#6
If there is a direct way with ByteArray.. will be better
There is the TinyGPS++ library that handles all the tokenizing and conversion to appropriate types for you.
system
December 14, 2014, 3:54pm
#7
strtok() will be right having a String, therefore convertion is necessary
in TinyGPS++ library aren't get functions
zoomkat
December 14, 2014, 4:09pm
#8
I copied the below from somewhere in the past, which might be of use.
String myString = String((char*)myByteArray);
//or
void setup(void)
{
}
void loop(void)
{
byte byteArray[5];
strcpy((char *)byteArray,"0123");
String myString = String((char *)byteArray);
}
KenF
December 14, 2014, 4:23pm
#9
zoomkat:
String myString = String((char*)myByteArray);
That sounds like a song.
“Only trouble is, String string, I’m stringing my bytearray.”
Everly Brothers?
system
December 14, 2014, 5:57pm
#10
String of Pearls !
Thanks, with TinyGPS++ lib i get marvelous output on Oled.
Also, I find that strtok() works just fine on char arrays. I find using the String class is only useful if you need a crutch.