We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi guys I'm new with Processing development and I having some problems. here's the issue: I'm using an Arduino to measuere temperature and just wanna to send it to Processing by serial communication and store it in to a .txt file. I have already searched a solution in Processing tutorials and in this forum, but didn't find yet. Any help is welcome!! Here is my code (the comments are in Portuguese):
//Ler os dados da porta serial e salvar num arquivo .txt import processing.serial.*; import cc.arduino.*; Serial portaCOM5; //Cria um objeto da classe Serial String dados, COM5; //Dados em ASCII recebidos do Arduino int val ;// Dados recebidos pela porta serial //Banco de dados PrintWriter arquivo; void setup () { size (200, 200); frameRate(10); println(Serial.list ()); //Lista no Prompt de Comando todas as portas seriais disponíveis COM5 = Serial.list()[0]; //Recebe a porta USB escolhida portaCOM5= new Serial(this, "COM5", 9600); //taxa de transfarencia 9600bps portaCOM5.bufferUntil('\n'); //Banco de dados: arquivo = createWriter("temperaturas"+"_"+month()+"-"+day()+"-"+year()+"_"+hour()+"-"+minute()+"-"+ second()+".txt"); //cria um arquivo para armazenar as temperaturas arquivo.print("Monitoramento de Temperatura DHT11"); arquivo.println(); } void draw() { background (255); //Ajusta cor de fundo como branca } void serialEvent(Serial portaCOM5) { COM5= Serial.list()[0]; //Recebe a porta USB escolhida while (portaCOM5.available()>0) { val = portaCOM5.readString(); arquivo.println(); } arquivo.flush(); // Writes the remaining data to the file arquivo.close(); // Finishes the file }
PS: When I check the monitor serial from Arduino, the data are there, so I believe anything here is wrong.
Thanks!!!!
Answers
Hey Pedro! I don't have Arduino nor any valid serial port here. So I can't be of much help.
Just did this very simple sample below. The idea is just to get 10 line readings.
After that, issue saveStrings() and end the sketch. Check it out whether it works for ya: :-\"
https://Processing.org/reference/saveStrings_.html
https://Processing.org/reference/trim_.html
https://Processing.org/reference/libraries/serial/index.html