Good to hear most of your errors are resolved! Regarding your question, Serial has indeed been deprecated in the mbed OS, and the recommended replacement is to use the BufferedSerial or UnbufferedSerial classes, depending on your needs.
Here’s an example of how you can replace your Serial usage with BufferedSerial:
cpp
Copy code
#include "mbed.h"
// Create a BufferedSerial object
BufferedSerial pc(USBTX, USBRX, 9600); // Specify TX, RX pins and baud rate
int main() {
pc.write("Hello, World!\r\n", 15); // Example of sending data
while (true) {
// Your application logic here
}
}
Key Notes:
Why BufferedSerial?
It provides an efficient way to handle serial communication, particularly with its buffer for RX/TX, minimizing data loss.
Suitable for higher baud rates and interrupt-based handling.
For Simpler Use:
If buffering isn’t critical, you can use UnbufferedSerial in the same way, but you’ll need to handle data carefully since it lacks internal buffering.
Documentation Reference
You can find more details in the mbed official documentation.
Let me know if you face any issues or need further assistance. Happy coding!
I’m getting ‘too many arguments’ error now. Just for reference, all I’m doing here is spitting out to Teleterm the codes and data from the remote control for debugging/dev purposes. Under normal operation, this is disabled (I am using mbed LPC1114).
There are just two parametr - a buffer of chars and its size. So there is not possible to do something similar like with printf function. So you need something like this - cplusplus.com/reference/cstdio/sprintf/
And code will look like this
char buffer [50];
int n, a=5, b=3;
n=sprintf (buffer, "%d plus %d is %d", a, b, a+b);
pc.write(&buffer, n);
But I believe the guy with the chatGPT will explain it better again
It looks like the error is occurring because the compiler can’t find the declaration for one or more of the variables (vendor_id, pair_command, address, command, or stop_bit) that you’re trying to use in the pc.write() statement.
Here are a few things to check:
Variable Declaration: Ensure that the variables (vendor_id, pair_command, address, command, stop_bit) are declared before the pc.write() line and are in the correct scope. They should be defined and initialized properly before using them.For example:
cpp
Copy code
int vendor_id = 123;
int pair_command = 456;
int address = 789;
int command = 101112;
int stop_bit = 1;
Include the Correct Header: Make sure that the header file for BufferedSerial is included properly at the top of your file. It should look something like this:
cpp
Copy code
#include "mbed.h"
Check for Typo: Verify that the variable names match exactly between the declaration and the pc.write() call (case sensitivity matters).
Format String: Your format string uses "%d" to print integers, but be sure that the values you’re passing are indeed of type int. If any of them are not integers, you’ll need to adjust the format specifier accordingly.
Once you’ve verified these points, the error should be resolved.
It looks like the error is occurring because the compiler can’t find the declaration for one or more of the variables (vendor_id, pair_command, address, command, or stop_bit) that you’re trying to use in the pc.write() statement.
Here are a few things to check:
Variable Declaration: Ensure that the variables (vendor_id, pair_command, address, command, stop_bit) are declared before the pc.write() line and are in the correct scope. They should be defined and initialized properly before using them.
For example:
cpp
Copy code
int vendor_id = 123;
int pair_command = 456;
int address = 789;
int command = 101112;
int stop_bit = 1;
Include the Correct Header: Make sure that the header file for BufferedSerial is included properly at the top of your file. It should look something like this:
cpp
Copy code
#include "mbed.h"
Check for Typo: Verify that the variable names match exactly between the declaration and the pc.write() call (case sensitivity matters).
Format String: Your format string uses %d to print integers, but be sure that the values you’re passing are indeed of type int. If any of them are not integers, you’ll need to adjust the format specifier accordingly.
If you’re working on projects like this and need advanced web development or web solutions, feel free to explore how professional services can streamline your workflow.