The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
Serial communication with FTDI Breakout Reloaded V1.1
i bought the following breakout board and want to communicate serial with my windows application and the netudino.
I wired the RX-Port from the breakout board with Digital Pin 0 and the TX-Port with the Digital Pin 1. Gnd to Gnd. I hoped the wiring is the same like here.
When i send a send a message with SerialPort.Write("blaa"), the breakout board receives a signal, the led on the board blinks but my netduino recieves no data.
Code on Netduino:
using System.IO.Ports;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using System.Threading;
namespace NetduinoStepperControl
{
public class Program
{
static SerialPort serial;
public static void Main()
{
// initialize the serial port for COM1 (using D0 & D1)
serial = new SerialPort(SerialPorts.COM1, 115200, Parity.None, 8, StopBits.One);
// open the serial-port, so we can send & receive data
serial.Open();
// add an event-handler for handling incoming data
serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
serial.ErrorReceived += new SerialErrorReceivedEventHandler(serial_ErrorReceived);
// wait forever...
Thread.Sleep(Timeout.Infinite);
}
static void serial_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
Debug.Print(e.ToString());
}
static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Debug.Print("Data received");
// create a single byte array
byte[] bytes = new byte[1];
// as long as there is data waiting to be read
while (serial.BytesToRead > 0)
{
// read a single byte
serial.Read(bytes, 0, bytes.Length);
// send the same byte back
serial.Write(bytes, 0, bytes.Length);
}
}
}
}
Code in Application:
using System;
using System.IO.Ports;
using System.Threading;
using System.Text;
using System.Diagnostics;
namespace Plugin{
[System.Serializable()]
public class NetduinoControllerPlugin : System.MarshalByRefObject, IControllerPluginService
{
static SerialPort _serial;
private String _name = "Netduino Controller Service";
public String Name
{
get { return this._name; }
set { this._name = value; }
}
private String _description = "foo";
public String Description
{
get { return this._description; }
set { this._description = value; }
}
public void Initialize()
{
Console.WriteLine("Initialize called");
try
{
_serial = new SerialPort("COM3", 115200, Parity.None, 8, StopBits.One);
_serial.DataReceived += new SerialDataReceivedEventHandler(_serial_DataReceived);
_serial.ErrorReceived += new SerialErrorReceivedEventHandler(_serial_ErrorReceived);
_serial.Open();
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e);
}
//Thread.Sleep(Timeout.Infinite);
}
void _serial_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
Console.WriteLine(e.ToString());
}
static void _serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// wait a little for the buffer to fill
System.Threading.Thread.Sleep(100);
// create an array for the incoming bytes
byte[] bytes = new byte[_serial.BytesToRead];
// read the bytes
_serial.Read(bytes, 0, bytes.Length);
// convert the bytes into a string
string line = System.Text.Encoding.UTF8.GetString(bytes);
// write the received bytes, as a string, to the console
System.Console.WriteLine("echo: " + line);
System.Console.WriteLine();
}
/// <summary>
/// double deg, int onTime, int offTime, bool onFirst, uint repeat
/// </summary>
/// <param name="deg" example="180 -> 180 degree to left">0, 10, 100, 360, -360, -100, -10, 0</param>
/// <param name="onTime" example="100 -> 100ms">0 - x</param>
/// <param name="ofTime" example="100 -> 100ms">0 - x</param>
/// <param name="onFirst" example="0 -> false" example="1 -> true"></param>
/// <param name="repeat" example="1 -> repeats once">0, 1, 2, ...</param>
public void MoveUp(int steps)
{
Console.WriteLine("MoveUp {0} Steps", steps);
String msg = steps + ",1,1,1,1";
_serial.Write(Encoding.UTF8.GetBytes(msg), 0, msg.Length);
}
Also, try a lower baud rate first. The higher the rate, the higher the likeliness of errors.
Furthermore, when serial is not working, always try swapping the cables, the question of wether TX or RX is the signal going in or out from where is always a matter of who's team you're playing for.
In analogy, according to the nazi's, Adolf was the good guy
Sorry for the unintentionally possibly rude joke that will probably get me banned from here. If it does, let me just say, I'm originating from Austria, so it was all on my own expense really.
Hi an thanks for the answers.
I tried to swapping the cables, same problem. The lower baud rate also didn´t work. I am no electronic guy, but the setup with this breakout board should work? Or have i bought the wrong hardware?
Thanks and best greetings,
Daniel
I tried to swapping the cables, same problem. The lower baud rate also didn´t work. I am no electronic guy, but the setup with this breakout board should work? Or have i bought the wrong hardware?
Thanks and best greetings,
Daniel
What is the switch on the side set for? It switches between 3.3v and 5v. If you are using it on Com1 it should be set for 3.3v.
What is the switch on the side set for? It switches between 3.3v and 5v. If you are using it on Com1 it should be set for 3.3v.
Is switches between 3.3v and 5v, right. I have it set on 3.3v. I also tried to use Digital Port 2 and 3, but same problem there. After work i will try a code from the net that should work with an USB BUB, seen here
Is switches between 3.3v and 5v, right. I have it set on 3.3v. I also tried to use Digital Port 2 and 3, but same problem there. After work i will try a code from the net that should work with an USB BUB, seen here
Maybe my code is wrong.
Greetings
I am using a different FTDI board from SparkFun but probably uses the same chips. I have it wired to pins 0 & 1 and my wires are crossed (TX = > RX and RX => TX).
The code I am using works fine here are some clips.
My Static Members
// The serial port
static SerialPort _port;
// current data position and packet length
static int count, readLength;
// Are we reading data from the port
static bool reading = false;
// Send data back to forms app or not
static bool bounce = false;
// Storage for our incoming data
static byte[] inTray;
Create and Open Serial Port
// Define the port, "COM1" Netduino digital pins D0(RX), D1(TX) at 115200 Baud
_port = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.One);
_port.DataReceived += new SerialDataReceivedEventHandler(ReceivedData);
_port.Open();
My Receive Event Handler
static void ReceivedData(object sender, SerialDataReceivedEventArgs e)
{
//Debug.Print("Data Received");
// Get the number of incoming bytes
int bytes = _port.BytesToRead;
// Create a new temporary store
byte[] data = new byte[bytes];
// Read in the bytes
_port.Read(data, 0, bytes);
// Check to see if this is a new read
// if so reset the system and get the
// length of the incoming data
if (!reading)
{
reading = true;
count = 0;
readLength = data[0];
inTray = new byte[readLength + 1];
}
// Populate the inTray with the incoming data
for (int i = 0; i < bytes; i++)
{
inTray[count] = data[i];
count++;
}
// Check to see if we have a full packet
ParseRecievedData();
}
Then I parse out the data
private static void ParseRecievedData()
{
// Check to see if we have a full packet. If so reconstruct data as text
if (count > readLength)
{
//Debug.Print("Parse Received Data");
// Remove the first byte as this is the length indicator
// not part of the message
byte[] outTray = new byte[inTray.Length - 1];
Array.Copy(inTray, 1, outTray, 0, outTray.Length);
// Convert the bytes back into a string
string text = new string(Encoding.UTF8.GetChars(outTray));
// Reset the reading state
reading = false;
// Use our new data to do something
DoSomethingWithData(text);
}
}
Then finally my DoSomethingWithData method has a switch to run different commands based on the text received. I don't recall exactly where I saw this example but it does work and works well at 115200 baud. I've had it even higher baud for simple one word commands.
no way.
I tried an working code but the netduino don´t respond. Also if i pinging the netduino (serial) over the MFDeploy Tool, "Error: no response from device"
Should i upgrade the firmware? Actual Firmware version on my netduino is 4.1.0.6
Maybe my netduino or the ftdi is broken but both are nearly new.
Greetings,
Daniel
I tried an working code but the netduino don´t respond. Also if i pinging the netduino (serial) over the MFDeploy Tool, "Error: no response from device"
Should i upgrade the firmware? Actual Firmware version on my netduino is 4.1.0.6
Maybe my netduino or the ftdi is broken but both are nearly new.
Greetings,
Daniel
When I started I was using 4.1.1 b1 because of another issue and I know it worked with that. I'm not sure if it worked with 4.1.0.6.
Here is a crazy question, do you have the FTDI's ground connected to Netduino ground?
I upgraded my firmware this evening with the new beta firmware Version: 4.2.0 RELEASE CANDIDATE (version 4.2.0.0 RC4)from here. There was a exciting 1 hour procedure but finally the firmware works
The problem with the serial connection is the same. I can send via COM3 to the FTDI, the "TX"-LED on the FTDI blinks if i send a message but there is no reaction from the netduino.
I ordered a "USB BUB" this evening. This FTDI must work.
The next step, i´d like to connect the FTDI and the netduino on a other PC and try it there.
This cable talks to the Netduino UART on a 3.3V TTL level and it always works very well for me. It is starting to sound as if your FTDI breakout board is broken.
Do you now get a response when pinging the device from MFDeploy? This is a reguirement for anything else to work.
Good Morning,
no i didn´t test the ping yesterday after the firmware upgrade. I will test it today after work. I saw this cable earlier but it seems that there are only a few shops in Germany that sell such stuff. I ordered the USB BUB in Netherlands.
Is there a possibility to test my netduino if it is broken? As earlier mentioned, i am not that electronic guy and fairly new onto this. As i unboxed the netduino i connected two stepper shields and two stepper motors. Maybe i broke something because of wrong wiring? The two steppers works fine.
Is there a possibility to test my netduino if it is broken?
Well, if your N+ responds to MFDeploy pings and you can program it via the onboard USB, it should be fine. The Netduino is quite durable so I doubt there is anything wrong with yours. Try something really simple, like the Blinky:
EDIT: If you mean to test the UART in particular, you can always run a loopback test. To do this, simply bridge the tx and rx pins of the intended UART on your N+, then write an application that creates a serial port, sends a few bytes and verifies that the exact same bytes are also received ok.
Another silly question, but when you plug the FTDI board into your PC, does it show up in device manager and what does it show up as? I am just remembering that I had to install drivers on the PC because I was getting the same results as you in the beginning. I am using this breakout board and they had the drivers on the page for download. FDTI Basic Breakout
EDIT: If you mean to test the UART in particular, you can always run a loopback test. To do this, simply bridge the tx and rx pins of the intended UART on your N+, then write an application that creates a serial port, sends a few bytes and verifies that the exact same bytes are also received ok.
Thanks for the tip, i´ll try it later. Blinky and other applications working fine.
Another silly question, but when you plug the FTDI board into your PC, does it show up in device manager and what does it show up as? I am just remembering that I had to install drivers on the PC because I was getting the same results as you in the beginning. I am using this breakout board and they had the drivers on the page for download. FDTI Basic Breakout
The FTDI show up as an USB/Serial-Device as far as i know. Have to look at home. On the original product page are no drivers for download but on the product page for the earlier release of this board. Thanks for the answer, i´ll give it a try. Incidentally, in Germany exisiter a proverb. "There are no silly questions, only stupid answers." So thank you very much for your help.
Installing the Driver for the FTDI Board -> Don´t work
Installing the setup on an other PC -> Don´t work
Bridge the Ports on the N+ and send commands -> Works
So the N+ is ok. I think the FTDI is broken, may i can send it back. Hope the USB BUB from Netherlands arrives soon, so i can test it. Hope this time it will work.
I think i will test the FTDI-Board like the N+ with bridging the ports.