Skip to main content

Arduino Serial Communication (I)



What is Serial communication for ?
If you are looking for some way to make your Arduino talk with other devices or to be able to be controlled by your computer, then you should have a look of serial communication! Serial is used for communication between the Arduino board and a computer or other devices.
 
Serial communication is a kind of “way” for devices to talk to each other. For example, if you build a temperature sensing Arduino project, and wanted to transmit data to the computer. Or controlling LED light on Arduino by computer. Then you might find it useful.
Let’s try some simple code with serial communication. Open your Arduino IDE and upload these codes.
void setup() { 
  Serial.begin(9600); 
  Serial.println("Hello Aconcagua!"); 
} 
void loop() { 
} 
Click on the Serial Monitor button on the right hand site.
 

If everything goes well. Hello Aconcagua! will be printed on the your serial monitor screen.
 
If you see any "Align language" output on your screen. It might be because of the wrong  Baud rate setting. Try to set the baud rate to 9600 baud and restart the Arduino again.
In this example, we open up a Serial communication port with 9600 bps baud rate.
Serial.begin(9600);
And we send a few words from the Arduino back to your computer from your USB connection.
  Serial.println("Hello Aconcagua!");
What if we change the code into this:
void setup() { 
} 
void loop() { 
  Serial.begin(9600); 
  Serial.println("Hello Aconcagua!"); 
  delay(500); 
} 
You can see your Arduino keep saying hello to you
 

If you look at your Arduino, you can see The TX line keep blinking. It represents the data is transmitted from Arduino back to your computer.


Comments

Popular posts from this blog

Arduino CNC shield control Stepper motor with DRV8825

CNC shield is quite useful for stepper motor driving. Here, I demonstrated how to use simple arduino code to drive stepper motor with DRV8825. First, just simply mount CNC shield onto Arduino Uno. Make sure the direction of the shield was right, where both the USB port and power supply wire was on your left hand site. The blue wire is my power supply which can be connect to 12-36V of power source. Next step you can mount the DRV8825 chip onto the CNC shield. Make sure the DRV8825 chip goes like this direction. If you put the chip in the wrong direction, you will probably damage it. By adjusting the jumber underneath the DRV8825 chip, motors can be driven with different kind of microstepping mode. I put three number here so it means that I set it into 1/32 step driving mode. Which is the most precise  one of DRV8825. The motor can connect to the right site of the DRV8825. Plug in the usb to your computer and upload these coded which will generate...

Connect Arduino Wemos D1 ESP8266 to Internet/Wi-Fi Router

Connect ESP8266 to Wi-Fi Router Upload these code to your Arduino WeMos D1 ESP8266 W-Fi board. #include <ESP8266WiFi.h> //SSID of your network char ssid[] = " myRouter"; //SSID of your Wi-Fi router char pass[] = " myPassWord"; //Password of your Wi-Fi router void setup() {   Serial.begin(115200);   delay(10);   // Connect to Wi-Fi network   Serial.println();   Serial.println();   Serial.print("Connecting to...");   Serial.println(ssid);   WiFi.begin(ssid, pass);   while ( WiFi.status() != WL_CONNECTED) {     delay(500);     Serial.print(".");   }   Serial.println("");   Serial.println("Wi-Fi connected successfully"); } void loop ( ) {} Using ESP8266 to connect to Wi-Fi need to use the function of: WiFi.begin(ssid, pass); // connect to target Wi-Fi SSID is the name of the Wi-Fi you want to connect to.  while ( ...

Setting up CUDA 10.0 for mxnet on Google Colaboratory

Preface Recently, I was trying to train model on Google Colaboratory with mxnet. However, I found the CUDA version pre-installed on the Colab. is 10.2. Till now, mxnet only support to CUDA 10.1 Therefore, I started to think about if it is possible to setup the environment that mxnet has support. Till now CUDA 10.1 doesn’t work for me. But I do successfully installed CUDA 10.0. Also tried to trained a LeNet on Colaboratory. Since I am a mac user, NVIDIA GPU is always what we are jealous and envy. Until I found Google Colaboratory…. I’d like to share my journey with you, if you also encounter some problem on setting up environment. Google Colaboratory provide free access to the NVIDIA Tesla K80 GPU (24GB RAM, 4992 CUDA core) . It is a great gift for most of people who is eager to learn deep learning but doesn’t have good hardware systems to train deeper models. NVIDIA Tesla K80 GPU I assume that you already have background knowledge of Python and familiar with tools like jup...