Problem with communication between Arduino and Processing

edited January 2017 in Arduino

I created this simple code with Arduino Ide where i send temperature in my serial monitor.

int tmpin = A0;

void setup()
{
 pinMode(tmpin, INPUT);
 Serial.begin(9600);
}

void loop()
{
  //Serie di calcoli per arrivari prima alla tensione e poi alla temperatura
  int value = analogRead(A0);
  float voltage = (value / 1024.0) * 5.0;
  float temp = (voltage - 0.5) * 100;

  Serial.println(temp);
  delay(1000);
}

And later i wrote a code in processing to print the data in Processing:

import processing.serial.*;

//Serial port
Serial port;

float val;

void setup()
{
  String portname = Serial.list()[0];
  port = new Serial(this, portname, 9600);
}

void loop()
{
  if(port.available() > 0)
  {
    val = float(port.readString());
    println(val);
  }  
}

But nothing went writed in the box

Tagged:

Answers

  • Answer ✓

    In processing... you need to change loop with draw.

    Also you need to format your code. Select each code and hit ctrl+o. Ensure there is an empty line above and below each code block.

    Kf

Sign In or Register to comment.