collapse

* Posts Recentes

Amplificador - Rockboard HA 1 In-Ear por almamater
[Ontem às 19:13]


O que é isto ? por KammutierSpule
[26 de Março de 2024, 19:35]


Bateria - Portátil por almamater
[25 de Março de 2024, 22:14]


Emulador NES em ESP32 por dropes
[13 de Março de 2024, 21:19]


Escolher Osciloscópio por jm_araujo
[06 de Fevereiro de 2024, 23:07]


TP4056 - Dúvida por dropes
[31 de Janeiro de 2024, 14:13]


Leitura de dados por Porta Serie por jm_araujo
[22 de Janeiro de 2024, 14:00]


Distancia Cabo por jm_araujo
[08 de Janeiro de 2024, 16:30]


Meu novo robô por josecarlos
[06 de Janeiro de 2024, 16:46]


Laser Engraver - Alguém tem? por almamater
[16 de Dezembro de 2023, 14:23]

Autor Tópico: Gravar TXT  (Lida 12166 vezes)

0 Membros e 1 Visitante estão a ver este tópico.

Offline brunomartins

  • Mini Robot
  • *
  • Mensagens: 19
  • "There is a way to be good again"
Gravar TXT
« em: 23 de Maio de 2009, 23:59 »
Pessoal, alguém tem alguma dica de como gravar em um arquivo TXT usando arduino?

Achei esse codigo na internet, mas não estou conseguino compilar, e não estou conseguindo resolver o erro..

Código: [Seleccione]
/**
 * Analog In
 *
 * Reads a value from the serial port and sets the background color.
 * Running this example requires you have a BX-24 microcontroller
 * and peripheral hardware. More information can be found on the tutorial
 * pages of Tom Igoe: http://stage.itp.nyu.edu/~tigoe/pcomp/examples.shtml
 * Because this program uses the serial port, it will not work within a web browser.
 *
 * Temperature collecting and writing to a text file
 */
 
import processing.serial.*;

String buff = "";
int val = 0;
int NEWLINE = 10;
int i = 0 ;
PFont font;
Serial port;


PrintWriter output;

void setup()
{
  size(250, 200);
  background(255, 204, 0);
  font = loadFont("UniversLTStd-Light-48.vlw");
  textFont(font, 32);

  // Print a list in case COM1 doesn't work out
  println("Available serial ports:");
  println(Serial.list());

  //port = new Serial(this, "COM1", 19200);
  // Uses the first available port
  port = new Serial(this, Serial.list()[0], 9600);
  output = createWriter("temperaturas.txt"); // cria arquivo para armazenar as temperaturas
}

void draw()
{
  while (port.available() > 0) {
    serialEvent(port.read());
  }
 
 
}

void keyPressed() { // Press a key to save the data
  output.flush(); // Write the remaining data
  output.close(); // Finish the file
  exit(); // Stop the program
}

void serialEvent(int serial)
{
  // If the variable "serial" is not equal to the value for
  // a new line, add the value to the variable "buff". If the
  // value "serial" is equal to the value for a new line,
  //  save the value of the buffer into the variable "val".
 
   
    println(serial) ;
    val=serial ;
    // Escreve a temperatura e a hora
    //
    output.println(hour() + ":" + minute() + ":" + second() + "," + val);

    //line(i,200,i,200-(val*4)) ; // funciona bem para a linha
    fill(102,0,153) ;
    rect(i,200-(val*4),2,val*4) ; // desenha a barra temperatura
   
    fill(255, 204, 0) ;
    noStroke() ;        // nao desenha a borda do retangulo .
    rect(110,5,50,30) ; // apaga o texto anterior
    fill(102,0,153) ;
    text(val, 125, 30);
    fill(0, 102, 153);

    i+=6 ;             // se chegar ao limite da area de desenho , apaga tudo e recomeça
    if(i>=250) {
      i=0 ;
      background(255, 204, 0);
    }
   
   
}

_______________________________
Bruno Martins

Offline Njay

  • Mini Robot
  • *
  • Mensagens: 3.598
    • Tróniquices
Re:Gravar TXT
« Responder #1 em: 24 de Maio de 2009, 00:25 »
Esse código não é para Arduino, por isso não consegues compilar.

O Arduino em si não consegue gravar ficheiros no PC. A única maneira é haver um programa no PC que recebe dados do Arduino por porta série e os grava num ficheiro. Para isso podes usar o Processing (muito usado com o Arduino) ou qualquer outra linguagem de programação que possa aceder a uma porta série do PC.

Offline guibot

  • Mini Robot
  • *
  • Mensagens: 651
    • Guibot
Re:Gravar TXT
« Responder #2 em: 24 de Maio de 2009, 00:37 »
brunomartins esse código é de Processing.

como o NJay disse com o Processing facilmente lês informação do arduino e gravas TXT's.

Offline brunomartins

  • Mini Robot
  • *
  • Mensagens: 19
  • "There is a way to be good again"
Re:Gravar TXT
« Responder #3 em: 25 de Maio de 2009, 13:11 »
como fazemos então para o Arduino salvar os dados em um cartão SD?
se ele não salva em TXT?

Tenho um sistema que tem que trabalhar independente do PC, ele não vai estar ligado no PC o tempo inteiro... não vou conseguir fazer ele gravar no sd?
_______________________________
Bruno Martins

Offline TigPT

  • Administrator
  • Mini Robot
  • *****
  • Mensagens: 5.372
    • Tiago Rodrigues
Re:Gravar TXT
« Responder #4 em: 25 de Maio de 2009, 13:22 »
Qualquer sistema que grave dados num cartão SD, pode gravar como txt pois um txt é simples ascii.

Tens aqui como gravar em pen usb:
http://www.arduino.cc/playground/Main/UsbMemory

Offline brunomartins

  • Mini Robot
  • *
  • Mensagens: 19
  • "There is a way to be good again"
Re:Gravar TXT
« Responder #5 em: 25 de Maio de 2009, 13:38 »
TigPT,

Então, se eu colocar o Arduino com o SD ele vai salvar em TXT normalmente?

Não vou precisar do processing no PC?

Uma outra duvida, tem alguma biblioteca que retorna a data e hora atual do sistema, na hora que ele estiver salvando os dados?
_______________________________
Bruno Martins

Offline TigPT

  • Administrator
  • Mini Robot
  • *****
  • Mensagens: 5.372
    • Tiago Rodrigues
Re:Gravar TXT
« Responder #6 em: 25 de Maio de 2009, 13:41 »
Sim, pode gravar para o SD como txt.

Para data, pode utilizar esta biblioteca:
http://www.arduino.cc/playground/Code/DateTime
ou um real time clock:
http://lusorobotica.com/index.php/topic,681.0.html