Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Phuong Vo
Published © MIT

How to Get String Data from Computer via Serial Port

This project helps you to send strings from computer to your Arduino via serial port.

BeginnerProtip1 hour24,874
How to Get String Data from Computer via Serial Port

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
You could use any other Arduino board. It just so happens that I have this one
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Serial Code

Arduino
#define LF          0x0A 

char angle_str[10]; 
int idx; 

void setup() {
    Serial.begin(9600);
    Serial.print("start\r\n");

    idx = 0;
}

void loop() {

    if (Serial.available() > 0) {
    angle_str[idx] = Serial.read();
    if (angle_str[idx] == LF) {
        Serial.print("Received new angle: ");
        angle_str[idx-1] = 0;
        Serial.println(angle_str);
        idx = -1;
        }
    idx++;
    }
}

Credits

Phuong Vo
4 projects • 10 followers
Hi
Contact

Comments

Please log in or sign up to comment.