Serial port programming in Galileo - arduino

I am new to Intel Galileo. I am trying simple things. How do I use serial TX(Digital pin 1) and serial RX(Digital pin 0) for communicating with other UART devices ? Which serial port is this UART ?
I tried to connect it by configuring it as uart 0/1/2 but did not work.
void setup() {
Serial1.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial1.println("Hello Galileo");
delay(300);
}

I have never used the Galileo but I was not aware that it had more than 1 serial port. So basing my thinking on the UNO as well as the MEGA, pin 0 and 1 should not be Serial1 but just Serial, meaning that if you connect the TX pin to the RX pin of another device and then, as you posted above, run your code with Serial.begin(9600); and Serial.println.... instead of Serial1.... it should work as far as I know... Also, I sometimes use Serial.Write but I am unsure of what the difference is. I normally would not answer a question I don't know the exact solution to but as there are no answers yet I thought I would give it a try.

I'm using a Gen2 and the latest build of Windows IoT (9600.16384.x86fre.winblue_rtm_iotbuild.150309-0310_galileo_v2). In that build, Serial is the correct object for COM1 on pins D0 and D1 and I've used it successfully.
Serial1 is supposed to be COM2 on D2 and D3, but I get an error when I try to open it. I'm still working on that.

Related

Arduino Nano no serial communication SIM800C

I am trying to get my SIM800C to talk with my Arduino. There is no communication happening, though.
#include <SoftwareSerial.h>
SoftwareSerial at(2, 3);
void setup() {
Serial.begin(9600);
at.begin(9600);
}
void loop() {
// try every 2 seconds
delay(2000);
Serial.println("sending AT ... ");
at.println("AT");
while (at.available() > 0) {
Serial.write(at.read());
}
}
I am not able to get an OK back. SIM800C is supposed to detect the baud rate by itself.
I am sure there has to be a simple stupid mistake. I just don't know what to do at this point. I obviously already checked for cable break. Out of desperation I already tried to switch RX and TX. I also tried different baud rates (whatever is within the usual limitations of SoftwareSerial) but it should automatically detect it once a couple of AT commands got in anyway.
Weird enough, the pin PWX on the SIM800C needs to be hooked up to a GND to work. It started blinking every second now and is responding to AT commands.
Also it turned out that this specific module does not ship with autobauding enabled, as stated by the SIM800C documentation. The correct baud rate is 115200.
There are some problems you need to consider:
Use below sample code which transfers data between PC and SIM. Sometimes SIM module would go into power down state and won't respond on any AT command but would print some results in the serial monitor.
As already mentioned in comments it seems that your wiring is wrong and as you declared Software Serial as SoftwareSerial at(2, 3); which means pin 2 is Rx on Arduino and should connect to Tx pin of SIM and pin 3 is Tx on Arduino and should connect to Rx pin of SIM. Please don't mess with the pins and connect the pins like below correctly.
Arduino SIM
Rx 2 ----> Tx
Tx 3 ----> Rx
I'm not sure if you can power on SIM800 with a 500mA USB connector, make sure that use an external 1/2 A power supply for VCC of SIM module.
Look at the blink speed of SIM module if it connected and powered on it would blinky with 3 seconds delay and if it blinks fast, it means that it is being restarted. Also if SIM powered on correctly it would print some info like SIM READY, CALL READY, etc.
Try other baud rates like 115200 and see if you get anything on power on.
I put some macro definition to make pin mappings more clear.
#include <SoftwareSerial.h>
//SIM800 TX is connected to Arduino D2
#define SIM800_TX_PIN 2
//SIM800 RX is connected to Arduino D3
#define SIM800_RX_PIN 3
//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
//Being serial communication witj Arduino and SIM800
serialSIM800.begin(9600);
delay(1000);
Serial.println("Setup Complete!");
}
void loop() {
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
Yes this module will not work in this configuration. There is a pin of V_TTL With 5V pin.. This pin enables the TTL logic converter of your GSM.. You have to connect this pin to 5V in case of arduino and to 3V in case of ESP8266.See the pin configuration here

Raspberry Pi 3 not receiving from Arduino Mega over GPIO UART

I'm trying to connect my Raspberry Pi 3 to an Arduino Mega 2560 over UART using the Rx and Tx pins (not USB cable). I went through all the steps to configure the Raspberry Pi to use the GPIO pins (https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/). For now, I'm just trying out the simplest code I can think of to make sure the connection is working (which it is not).
Arduino code:
void setup() {
Serial.begin(9600);
Serial.println("Start");
}
void loop() {
Serial.write(".");
}
Raspberry Pi code:
import serial
ser = serial.Serial('/dev/serial0', 9600)
while 1:
x = ser.readline()
print x
It's not giving me any errors or anything, but when I run the python code on the Raspberry Pi I get nothing. I'm using a logic level converter between the Pi and Arduino. Using a multimeter, I found that there is a signal going from the Arduino to the Pi, which is around 2.5V. Is this enough for the Pi? Could this be the problem? If so, what is causing it? I used 2 different Arduinos and I'm getting the same result from both.
I just don't understand what I'm doing wrong here and would really appreciate it if someone could help.

how to get AT response from ESP8266 connected to arduino

I am fighting with ESP8266 wifi module and connecting arduino. After updating firmware to newest version i started to programm arduino to get data incoming from wifi. I saw many examples about maiking webserver via ESP8266 but none of them works for me.
ESP is connected to my Arduino Leonardo:
>
Arduino -> ESP8266
power 3.3V -> vcc
ground -> ground
tx -> rx (via logic level converter 5->3.3V)
rx -> tx (via logix level converter
power 3.3V ->gpio0 (without any resistors)
I made simple sketch:
void setup(void){
Serial.begin(9600);
Serial1.begin(115200);
}
void loop() {
if(Serial1.available())
{
Serial.println("WIFI IS AVAILABLE");
Serial1.println("AT");
delay(1000);
} else {
Serial.println("WIFI not available.");
delay(1000);
}
}
After executing it ESP8266 is powered (red led is on) and also every second blue led (blinks). That makes me sure that in fakt "AT" command is transmited to module. But there are also two issues:
i want to get response from esp - in this case word "OK". I tried Serial1.read() but it only reads one byte. Serial1.readString() makes my messages "wifi not available" and sametimes "wifi is available" as if for a while the connection would be unavailable
after uploading sketch to arduino and having powered esp8266 wifi module is always unavailable - i need to power the module off and on again to have it working.
Anybody please can help me?
What you need to do is change your approach a bit. Do not check if data is available. The trick is to send the module something and then check for data.
Do something like:
while (Serial.available() > 0)
Serial.read();
to clear the buffer before any command you want to send. Then send the command. Then check for data as a response.
Do not rely on that Blue LED as any indication. It is only an indication that the ESP8266 is busy using the WiFi in some sort of way, whether it is doing keepalives, initializing WiFi or whatever. It can be totally unrelated to whatever you are sending. If you do not receive a valid response then you must assume that there is comms issues between you and the module. One thing though is that if that Blue LED never goes off then either the module has frozen or the firmware was corrupted. I have had that many times. I then reload the firmware and usually that fixes it. It usually only happens during development times where I reset, upload code or change wires.
I use mine with an atmega328 on a separate slef-built board and not the one on the Uno and run that board on 3.3v itself and then use a logic level converter between that atmega board and my Uno so that I can program it. But I have had sporadic issues with non-comms but I suspect it might be power related. Be aware that running your Serial via the logic level converter might also be causing comms issues.
Proposed wiring: All pins except RX,TX,VCC and GND goes to VCC via 10K pullup resistors. RX goes to the arduino's TX and TX goes to the arduino's RX. Of course you know where VCC and GND goes.

Arduino to Arduino communication via SoftwareSerial

I have two Arduino Leonardo.
Could these two Arduino boards communicate with each other by SoftwareSerial library? (Not Serial1, Thank you)
Yes you can use digital pins to do it. Simply connect both Tx to Rx
Yes, you can use any spare digital pins on each Arduino
Yes, of course. You can use all PWN Pins, 3, 5, 6, 10, 11, 13.
Yes but you always have to consider that Arduino is based on microcrontroler, not microprocessor so when you program it you should forget multitasking, every kind of multitasking attempt will come in unexpected behaviour (slowdown close to stuck).
In this case software serial communication will slow down program execution according to the volume of data received and it will be completely stuck during hardware serial communication.
To deal with that you should use the approach "one thing at time" in your code.
I hope it helped and didn't frighten.
There's is an example in the Arduino IDE under software serial that shows how to use it. It says to use digital pins 3 and 4 instead of the hardware serial pins 0 and 1. The sketch constantly reads the software serial and prints anything it reads to the serial monitor.
It wouldn't take much to adapt this code to run on a second Arduino to constantly write to Software Serial.
Yes! Simply use TX and RX pins of arduino. Connect the receiver TX, RX pins to RX, TX of the sender, respectively.
of course , just make sure to cross out RX and TX:
RX1 -> TX2
RX2 -> TX1
You can use any digital pins as software serial, in case i doesn't work, use pin 10, 11 for software serial.
You can use SerialTransfer.h to automatically packetize and parse your data for inter-Arduino communication without the headace. The library is installable through the Arduino IDE and includes many examples.
Here are the library's features:
This library:
can be downloaded via the Arduino IDE's Libraries Manager (search "SerialTransfer.h")
works with "software-serial" libraries
is non blocking
uses packet delimiters
uses consistentoverhead byte stuffing
uses CRC-8 (Polynomial 0x9B with lookup table)
allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 255 bytes)
can transfer bytes, ints, floats, and even structs!!
Example TX Arduino Sketch:
#include "SerialTransfer.h"
SerialTransfer myTransfer;
void setup()
{
Serial.begin(115200);
Serial1.begin(115200);
myTransfer.begin(Serial1);
}
void loop()
{
myTransfer.txBuff[0] = 'h';
myTransfer.txBuff[1] = 'i';
myTransfer.txBuff[2] = '\n';
myTransfer.sendData(3);
delay(100);
}
Example RX Arduino Sketch:
#include "SerialTransfer.h"
SerialTransfer myTransfer;
void setup()
{
Serial.begin(115200);
Serial1.begin(115200);
myTransfer.begin(Serial1);
}
void loop()
{
if(myTransfer.available())
{
Serial.println("New Data");
for(byte i = 0; i < myTransfer.bytesRead; i++)
Serial.write(myTransfer.rxBuff[i]);
Serial.println();
}
else if(myTransfer.status < 0)
{
Serial.print("ERROR: ");
Serial.println(myTransfer.status);
}
}
Yes you can use the pwm pins to communicate. It is recommended to not use 0,1 for serial communication as they are used to upload the sketches using the USB port into the Arduino.

xBee communication Arduino to Arduino

I have a realy weird problem with my xBee S1 Pro moduls. I used the XCTU software to configure them. I set one Arduino to recive data and the other one to transmit. When i use the XCTU Software to send some testframes, it works, the reciver gets the data. But if i want my arduinos to communicate it dosent work. I assume that the moduls are configured the right way because PC -> Arduino works. So i'll provide the Sketches so you can tell me whats going wrong
reciver
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0){
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
Serial.print("recived some data: ");
Serial.println(Serial.read());
Serial.flush();
}
}
and now the sender
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println("data");
Serial.flush();
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(4000);
}
whats wrong? any ideas?
I would check the connections to the Xbee, i.e. make sure that RX is actually connected to DOUT and TX is connected to DIN. Also if you are sending actual "Frames" then it sounds like you are running your xbees in api mode so you will need to do more then just send out "data" what you want is for it to be running in serial pass through mode.
One last thing to check is if you are using arduino Leonardo or Micro the hardware Serial port is Serial1 not Serial.
You're using the same Serial port for communicating with XBee and USB. That's the problem. You need to set another Serial port instead of the used for USB to communicate with XBee.
It will be good if you share what arduino boards and shields you are using.
So first thing is first... If these xBees have separate passcodes at a different baud rate, shit is going to happen. Also what command mode are these in (AT or API)? Factory default settings ? Accepting AT commands to change these ? (By default you are in AT mode)
Open a serial program (I use coolTerm for OS X ). Ensure to setup correctly of these steps.
Once you know these transmitters are talking at the same baud, passcode, etc... Ensure you have the code uploaded to your Arduinos BEFORE connecting these transmitters to the RX/TX pins with a simple serial read and write.
The code seems right, but make sure what you are trying to send. Xbees can transmit and receive 8bit data only.
First send a known byte of data such as a=100; and see whether this data receives there perfectly or not.

Resources