Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Simple Read
- *
- * Read data from the serial port and change the color of a rectangle
- * when a switch connected to a Wiring or Arduino board is pressed and released.
- * This example works with the Wiring / Arduino program that follows below.
- */
- import processing.serial.*;
- Serial myPort; // Create object from Serial class
- int val; // Data received from the serial port
- void setup()
- {
- size(200, 200);
- // I know that the first port in the serial list on my mac
- // is always my FTDI adaptor, so I open Serial.list()[0].
- // On Windows machines, this generally opens COM1.
- // Open whatever port is the one you're using.
- String portName = Serial.list()[5];
- printArray(Serial.list());
- myPort = new Serial(this, portName, 19200);
- }
- void draw()
- {
- while (myPort.available() > 0) {
- String inBuffer = myPort.readString();
- if (inBuffer != null) {
- String[] splittedList = split(inBuffer, ",");
- if (splittedList.length == 6) {
- float temperatureVolt = (unhex(splittedList[2]) / 10.0) * (68.0 + 39.0) / 39.0;
- float humidityVolt = (unhex(splittedList[3]) / 10.0) * (68.0 + 39.0) / 39.0;
- float voltage = int(trim(splittedList[5]))/1000.0;
- temperatureVolt /= 1000.0;
- humidityVolt /= 1000.0;
- print("VCC: "); print(voltage);
- print("\tTemp V: "); print(temperatureVolt); print("\tHumidity V: "); println(humidityVolt);
- float temperature = -45-(17.5/0.8)+(175/0.8)*(temperatureVolt/voltage);
- float humidity = -(10/0.8)+(100/0.8)*(humidityVolt/voltage);
- print(temperature);print("°C\t");
- print(humidity);println("%");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement