Netduino home hardware projects downloads community

Jump to content


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.

Nemanja

Member Since 12 Dec 2012
Offline Last Active May 30 2015 03:14 PM
-----

Topics I've Started

Serial communication problem

27 August 2013 - 05:04 PM

Hello everyone,

recently i bought jy-mcu usb to serial adapter for arduino, thinking that i could connect it to my netduino.

but i got some problems. Netduino sends and receives data, but only zeros. When pc sends data to netduino it receives only zeros, it also happend when netduino sends data to the computer.

I think the number of bytes that are send and receives is ok because when i send one letter from pc to netduino, he only receive one byte, when send two letter there are two bytes (two "0"s) and so on....

 

 

this is my code for netduino:
-----------------------------------------------------------------------------------------------------------------

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.IO;
using System.IO.Ports;

namespace NetduinoApplication9
{
  public class Program
  {
  static SerialPort port;
  public static void Main()
  {
  // write your code here
  port  = new SerialPort(SerialPorts.COM1, 9600, Parity.None,8 , StopBits.One);
  byte[] txtBuff = System.Text.Encoding.UTF8.GetBytes(t);
  port.ReadTimeout = 0;
  port.Open();
  port.DataReceived += new SerialDataReceivedEventHandler(Data_Received);
  OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
  for (int i = 0; i < 3; i++)
  {
  led.Write(true);
  Thread.Sleep(250);
  led.Write(false);
  Thread.Sleep(250);
  }
  Thread.Sleep(Timeout.Infinite);
 

 
  }

  static void Data_Received(object sender, SerialDataReceivedEventArgs e)
  {
  Thread.Sleep(100);
  byte[] b = new byte[1];
  while (port.BytesToRead > 0)
  {
  port.Read(b, 0, b.Length);
  port.Write(b, 0, b.Length);
  }
  }

  }
}

-----------------------------------------------------------------------------------------------------------------------------

 

 

and code for pc app:

------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication6
{
  public partial class Form1 : Form
  {

static SerialPort comport;

  public Form1()
  {
  InitializeComponent();
  }



  private void button1_Click(object sender, EventArgs e)
  {
// .Write("LED=1r");
  comport.Write("a");
  }

  private void Form1_Load(object sender, EventArgs e)
  {
  //com6 = new SerialPort("COM6", 9600, Parity.None, 8, StopBits.One);
  comport = new SerialPort("COM6", 9600 , Parity.None, 8, StopBits.One);
  comport.Open();
  comport.DataReceived += new SerialDataReceivedEventHandler(Data_Received);
  }

  private void button2_Click(object sender, EventArgs e)
  {
  comport.Write("LED=0r");
  }

  private void button3_Click(object sender, EventArgs e)
  {
  comport.WriteLine("3r");
  }

  static void Data_Received(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[comport.BytesToRead];
  // read the bytes
comport.Read(bytes, 0, bytes.Length);
  // convert the bytes into a string
  string line = System.Text.Encoding.UTF8.GetString(bytes);
  }
  }
}

-------------------------------------------------------------------------------------------------------------------------------------

 

adapter is connected with netduino like this

adapter netduino

TX   RX(D0)

RX   TX(D1)

  GND GND

 

there are also 3.3V, VBUS, DTR pins on adapter and i'm not really sure what they mean.

 

any advice would be appreciated.

Nemanja.
 


netduino-pic communication

13 December 2012 - 10:06 PM

Hello once again :) I'm wonder if it is possible to make communication between netduino and pic microcontroller? The idea is to use pic as usb to some type of communication protocol converter for netduino so he(netduino) can send and receive data from pc over pic. I already posses pic 18f4550 with build-in usb interface.

Strange analog readings

12 December 2012 - 05:04 PM

Hello netduino community. First off all because this is my first post i will introduce myself. I'm an IT student from Serbia, 24y old and name you can read. that was short :) So, here is the problem: short code loaded in to netduino: ------------------------------------------------ public class Program { static AnalogInput _analog1 = new AnalogInput(Pins.GPIO_PIN_A0); static AnalogInput _analog2 = new AnalogInput(Pins.GPIO_PIN_A1); static AnalogInput _analog3 = new AnalogInput(Pins.GPIO_PIN_A2); public static void Main() { _analog1.SetRange(0, 1000); _analog2.SetRange(0, 1000); _analog3.SetRange(0, 1000); while (true) { Debug.Print("AN_1: " + _analog1.Read().ToString()); Debug.Print("AN_2: " + _analog2.Read().ToString()); Debug.Print("AN_3: " + _analog3.Read().ToString()); Thread.Sleep(1000); } } } with no hardware attached to netduino i got strange readings on debuger output: ------------------------------------------------------------------------------------- AN_1: 1000 AN_2: 0 AN_3: 20 AN_1: 0 AN_2: 612 AN_3: 683 AN_1: 527 AN_2: 0 AN_3: 0 AN_1: 237 AN_2: 691 AN_3: 680 AN_1: 0 AN_2: 0 AN_3: 0 AN_1: 719 AN_2: 652 AN_3: 495 AN_1: 0 AN_2: 0 AN_3: 43 AN_1: 1000 AN_2: 379 AN_3: 243 AN_1: 0 AN_2: 183 AN_3: 288 AN_1: 1000 AN_2: 58 AN_3: 0 AN_1: 0 AN_2: 360 AN_3: 465 AN_1: 999 AN_2: 1 AN_3: 0 ----------------------------------------------------------------------------- any suggestions why is that happening? shouldn't there be all zeros? edited: measures are stable with hardware(potentiometer) connected.

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.