# Issue with reading Arduino Port

**URL:** https://discourse.processing.org/t/issue-with-reading-arduino-port/7846
**Category:** Electronics (Arduino, etc.)
**Created:** [January 25, 2019, 8:52pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846 "2019-01-25T20:52:38Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 25, 2019, 8:52pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/1 "2019-01-25T20:52:38Z")

</div>

I have a phototransistor and an LED, when I test in Arduino I do get readings from the phototransistor, but when trying to get the same readings in Processing I just get continuous 0’s. Can any one help? I’ve placed the code below. The phototransistor is connected to port A1. Thanks!

```auto
import cc.arduino.*;
import org.firmata.*;
import processing.serial.*;

int PhotoPin1 = 1;
Arduino port;
float W= 0;
void setup(){
  port= new Arduino(this, Arduino.list()[17], 9600);
  port.pinMode(PhotoPin1, Arduino.INPUT);
}

void draw() {
  
  float w_sensorRaw1= port.analogRead(PhotoPin1);
  println(w_sensorRaw1);
  println(W);
  delay(1000);
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 28, 2019, 3:08am UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/2 "2019-01-28T03:08:06Z")

</div>

@Ryan12,  
possibly this is first time you use serial interface in processing,  
and you started with a  
arduino ( firmata )  
example.

this ONLY can work if the arduino is loaded with the firmata sketch.

when you say that you see the data incoming  
in the arduino IDE monitor ( terminal emulator )  
you not have firmata loaded to arduino,  
you have your own code sending data continuously by serial.println()  
in that case you only use in processing the

`import processing.serial.*;`  
and how to setup see for a example for that library (only )

//\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
also can you tell us where the

> [@Ryan12](#):
>
> [17]

come from?  
it is good practice to first print the port list.

---

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 28, 2019, 2:43pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/3 "2019-01-28T14:43:40Z")

</div>

I had uploaded the firmata sketch to the Arduino, but I still was having the issue. The 17 comes from the list, I just had it commented out after I had it set. Also regarding using just serial, can I do that if I’m using one of the pins as an input, because I need to read it and then output what the pin’s value is?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 28, 2019, 2:51pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/4 "2019-01-28T14:51:50Z")

</div>

> [@Ryan12](#):
>
> I had uploaded the firmata sketch to the Arduino, but I still was having the issue. The 17 comes from the list, I just had it commented out after I had it set.

ok you want use FIRMATA  
check on what i just play [here](http://kll.engineering-news.org/kllfusion01/articles.php?article_id=158#here1)

---

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 28, 2019, 3:58pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/5 "2019-01-28T15:58:23Z")

</div>

ok thanks, I’ll take a look and see if it solves the problem!

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 29, 2019, 9:00am UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/6 "2019-01-29T09:00:53Z")

</div>

did you try my processing code example? with your firmata arduino?

---

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 29, 2019, 2:31pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/7 "2019-01-29T14:31:02Z")

</div>

I was away from my space yesterday but back today so I’m going to try it this afternoon and I’ll let you know. Thanks so much for following up

---

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 29, 2019, 5:23pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/8 "2019-01-29T17:23:28Z")

</div>

I tried your example and I still only get 0.0 values

---

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 29, 2019, 6:34pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/9 "2019-01-29T18:34:56Z")

</div>

it looks to me that despite having the correct port connected there is 0 connection to the Arduino. Code that has worked in the past is no longer working

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 30, 2019, 12:45am UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/10 "2019-01-30T00:45:09Z")

</div>

the reason why i made this version of code was to  
allow that loop back by making a jumper cable

> A0 ↔ D5

so when you click on the [D5] button the D5 output should change  
( what you also can verify with a voltmeter )  
and via that jumper cable the A0 input jump from  
0 to 5V ( what you should see in the _A0_ bar graph and the volt number…

//\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
if you think that your code has worked  
but now still runs, but show allways 0  
there might be a hardware / or port problem  
of the arduino board. But i only see burned out Douts  
( from a short circuit ) or arduinos what stopped working completely.

anyhow go back to  
Arduino IDE, load a blinky and a analog read example and test with the  
build in monitor.

---

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 30, 2019, 1:39pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/11 "2019-01-30T13:39:11Z")

</div>

Right so when I test analogRead in Arduino and just jump between 3.3V, 5V, and Ground the serial monitor shows it properly reading these values. I also got a Hello World to work with serial, and a primitive Serial read to show changing values code below:

```
import processing.serial.*;
import cc.arduino.*;

Serial myUno;

String w_sensorRaw1;

void setup() 
{ 
 println(Arduino.list());
 myUno= new Serial(this, Serial.list()[18], 9600);
 println(Arduino.list()[18]);
} 
 
void draw() 
{ 
   w_sensorRaw1= myUno.readStringUntil('\n'); 
   println(w_sensorRaw1);

delay(100);
} 

```

This gives me appropriate varrying outputs in Processing, but then if I simply change the commands to those associated with an Arduino I get 0 again.

```
import processing.serial.*;
import cc.arduino.*;

Arduino myUno;

  int w_sensorRaw1;

void setup() 
{ 
 println(Arduino.list());
  myUno= new Arduino(this, Arduino.list()[18], 9600);
  println(Arduino.list()[18]);
} 

void draw() 
{ 
   w_sensorRaw1= myUno.analogRead(0); 
   println(w_sensorRaw1);

delay(100);
} 

```

Any thoughts?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 30, 2019, 1:53pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/12 "2019-01-30T13:53:53Z")

</div>

> [@Ryan12](#):
>
> Any thoughts?

yes,

- in the first code you load the firmata lib to processing sketch but not use it,  
( and all lines what contain the word "arduino " should be removed )  
using the serial lib only works for you / as you test it against your own arduino code?? /

- in the second code you use the firmata lib,  
but not say that you uploaded firmata to arduino, so it can not work!

also when you tested my processing firmata example,  
did you upload the standard firmata to arduino first?  
like i show detailed in that many pictures blog extra for you?

---

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 30, 2019, 2:21pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/13 "2019-01-30T14:21:01Z")

</div>

Yes I did when I tested your code. Do I have to upload everytime?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 30, 2019, 3:21pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/14 "2019-01-30T15:21:24Z")

</div>

and when you test your second processing code  
( what also is a firmata code )  
you changed arduino also from your sketch to firmata?

when your processing gives you a 0.0, did you measure voltage at that arduino pin?

//\_\_\_\_\_\_\_\_\_\_\_\_  
anyhow i try to play with your "second code "  
and yes, i got 0 too!!

now that was bad, as i just

- loaded firmata

- test my sketch and connect A0 to 5V and all ok

- test your sketch and it did not work…  
so i play until i see something,  
it was the baud rate ! 57600 !  
see all arduino ( firmata ) examples have that rate and  
[http://playground.arduino.cc/Interfacing/Processing](http://playground.arduino.cc/Interfacing/Processing)  
here too, even suggest you can omit that parameter?

 ![2019-01-30_22-09-19_snap](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2dfb382cf451ba96080573483b523e09f5a7ee62.png)  
yes the first reading again was 0.  
but then it worked fine.

and that again let me think why my code did not work in your setup?

- did you do the jumper cable?
- did you press the button?

---

<div class="post-metadata">

### Author: ![Ryan12](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Ryan12](https://discourse.processing.org/u/Ryan12)
#### Post date: [January 30, 2019, 11:55pm UTC](https://discourse.processing.org/t/issue-with-reading-arduino-port/7846/15 "2019-01-30T23:55:31Z")

</div>

Got it to work finally. Thanks for all your assistance and patience!
