Using hw-658 gps module, hc-06 bluetooth / display latitude and longitude


스크린샷 2025-05-23 133709

arduino code

#include <TinyGPS++.h> //include TinyGPS library

#define GPS_SERIAL Serial3
#define BLUETOOTH_SERIAL Serial1
#define GPS_BAUD 9600
#define BLUETOOTH_BAUD 9600

TinyGPSPlus gps;
unsigned long lastLocationTime = 0;
unsigned long lastPrintTime = 0;

void setup() {
  Serial.begin(9600);
  GPS_SERIAL.begin(GPS_BAUD);
  BLUETOOTH_SERIAL.begin(BLUETOOTH_BAUD);
  Serial.println("start GPS and Bluetooth");
}

void loop() {
  while (GPS_SERIAL.available() > 0) {
    char c = GPS_SERIAL.read();
    gps.encode(c);
    Serial.write(c);

    if (gps.location.isValid()) {
      float lat = gps.location.lat();
      float lon = gps.location.lng();

      BLUETOOTH_SERIAL.print(lat, 6);
      BLUETOOTH_SERIAL.print(",");
      BLUETOOTH_SERIAL.print(lon, 6);
      BLUETOOTH_SERIAL.println();

      Serial.print("latitude: ");
      Serial.print(lat, 6);
      Serial.print(" / longitude: ");
      Serial.println(lon, 6);

      lastLocationTime = millis();
    }
  }

  if (millis() - lastLocationTime > 3000 && millis() - lastPrintTime > 3000) {
    Serial.println("no location data");
    BLUETOOTH_SERIAL.println("no location data");
    lastPrintTime = millis();
  }

  if (millis() > 10000 && gps.charsProcessed() < 10) {
    Serial.println("GPS Failed to receive data: Wiring or power check required");
    BLUETOOTH_SERIAL.println("GPS Failed to receive data: Wiring or power check required");
    while (true);
  }
}.

I'm working on using the gps module to display latitude and longitude values. I'm writing the Arduino code and operating it, but the error appears as follows. <runtime error | The operation length of list cannot accept the arguments:,[false]> I started without basic knowledge of the app inventer, so I'm not sure how to solve it. please help........

Be sure to use println() at the end of each message to send from the sending device, to signal end of message.

Only use print() in the middle of a message.

Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.

Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Some people send temperature and humidity in separate messages with distinctive prefixes like "t:" (for temperature) and "h:" (for humidity).
(That's YAML format.)

The AI2 Charts component can recognize these and graph them. See Bluetooth Client Polling Rate - #12 by ABG

To receive YAML format messages, test if the incoming message contains ':' . If true, split it at ':' into a list variable, and find the prefix in item 1 and the value in item 2.

Here is an updated blocks sample illustrating these ideas ...

BlueTooth_delimiter_sample.aia (3.4 KB) global message

I have to point out a particularly awful piece of code in your blocks, and where you went wrong.

image

  1. Setting the DelimiterByte should be done using a decimal number 10 for the NewLine, not \n.

  2. You used a green equality test block for the assignment. Though it looks like a C '=', it is just a test for equality, and returns True or False without changing the variable on the left.

  3. You assigned that true/false value into your gpsData variable, forgetting to test for BytesAvailable in the BlueTooth buffer.

  4. You forgot to conditionally issue a read text from BlueTooth, to retrieve the buffer contents
    up to the decimal 10 (\n) into the gpsData variable.

image