Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC to PC communication and value storage

Status
Not open for further replies.

PoS080

Junior Member level 3
Junior Member level 3
Joined
Apr 2, 2017
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
243
Hello EE friends,

I am thinking of starting a new project where I would like to use a microcontroller to communicate temperature readings from a temperature sensor that is connected to it to my pc and then have the pc store the data in a text file.

In the past I have experimented with ttl usb uart connection to display readings into putty, but have never saved or collected such data. What would be the best communication protocol?

I'm not sure how to approach this and was wondering if you helpful people could point me in the right direction or maybe critique my current approach.

What I have available to me PC windows 10 bluetooth enabled, pic16f1829: UART, I2C. temperature sensor. I am willing to buy more parts or chips.

I feel like I would have to have two programs one for the micro to send the data and then one running on the pc to receive and store?

Any insight?
 

This is a pretty slow process, so I don't see any reason to get bogged down in the intricacies of Bluetooth, USB, etc. Why not use a simple Rs-232/422 connection. Then you could write a simple program for the pc in VBA or matlab, or whatever.
 

Hi,

Maybe do the communication ASCII style, and TAB separated.
Then any terminal program may save the data stream into a file.

Klaus
 

What hardware would i need for this?

I was planning on just using UART and a CP2102 to connect my UART to USB
 

I now also have arduino uno. Will keep you guys updated on my progress.
 

What you have mentioned so far is all very "do-able".
What I'd like to know is which part are you having trouble with?
Susan
 

What you have mentioned so far is all very "do-able".
What I'd like to know is which part are you having trouble with?
Susan

Oh, I'm not having trouble with anything. I havent started yet. I was just trying to get some best practices and see how experts on the board would approach the problem.
 

You did not mention what language you are using on PC side, as almost everyone recommended best way is to communicate on Serial Port, for example if you use C# it has lots of built in libraries you can take advantage, after receiving data you can save on file or database.
 

I finished the project, in the end I ended up using an arduino UNO over PIC. So I ask the mods to change the thread title accordingly.

Devices used: UNO, CP 2102 UART to USB
languages: Java and Processing

How it works: The arduino reads and transmits data to the PC over CP2102. A separate script scans that COM PORT and stores value to PC either in text or CSV.

Code to program Arduino

Code:
int analogDevice   = 0; //Device connected to pin AN0

void setup()
{
  Serial.begin(9600);  //Serial Comm start at 9600 baud                     
}
 
void loop()                     
{
 //Grab inputs
 int deviceReading = analogRead(analogDevice);  

 ///////////////PRINT TO CLI//////////////////////
 
 // print out the voltage
 Serial.print("\n");//Newline
 Serial.print(deviceReading); Serial.print(","); //Comma as delimiter

 delay(1000); //Print Rate
}

Seperate code to read off a com port and store to file
Code:
import processing.serial.*;
Serial mySerial;
String val;
int x = 0;
PrintWriter output;
void setup() {
   mySerial = new Serial( this, Serial.list()[0], 9600);
   output = createWriter( "data.txt" );
   output.println("INPUT PROTOTYPE"); //HEADER
}
void draw() {
    if (mySerial.available() > 0 ) {
         String value = mySerial.readStringUntil('\n'); //Read until new line
         if ( value != null ) {
              output.println( value );
            x++; 
         }
    }

}

void keyPressed() {
    output.flush();  // Writes the remaining data to the file
    output.close();  // Finishes the file
    exit();  // Stops the program
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top