# \[SOLVED\] Problems sending data from Processing to Arduino through serial port

**URL:** <https://discourse.processing.org/t/solved-problems-sending-data-from-processing-to-arduino-through-serial-port/20138>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [April 25, 2020, 2:13pm UTC](https://discourse.processing.org/t/solved-problems-sending-data-from-processing-to-arduino-through-serial-port/20138 "2020-04-25T14:13:10Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 26, 2020, 3:33pm UTC](https://discourse.processing.org/t/solved-problems-sending-data-from-processing-to-arduino-through-serial-port/20138/3 "2020-04-26T15:33:08Z")

</div>

Hello,

I have done similar with BlueTooth (serial over BT) modules.

The first thing I do is make sure the code works connecting PC directly to Arduino using the USB serial.  
If this serial communication works then adapt the code (just change the serial ports) to work with Blue Tooth serial and in your case XBEE serial.

The challenge is to configure the hardware correctly and then test the serial communications (USB serial first and then BT or XBEE serial).

I have a lot of serial to USB modules I can use with the additional Arduino serial ports (Serial 1, 2, and 3 on my Mega 2560) to communicate with PC (serial USB) as monitors\listeneners; these come in handy. If you don’t have these you can light up LEDs or use LCD displays as a data monitor during initial testing.  
I often use a serial monitor\listener and that can be the Arduino monitor, other terminal software or even another Processing sketch.

I see that you are using software serial which also works.

You can also send data back using the same serial port; I usually do not do this as it can complicate code and troubleshooting.

I am assuming:

Xbee (serial) on PC  
XBee (serial) on Arduino  
USB(serial) on Arduino used to monitor received data.

Try these:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/73a1be564a11d8c0fb05499d7fac1bf54f64c2b9.png)

This is a “fix” for SimpleWrite example:

> [@Processing to Arduino Serial Library Example](https://discourse.processing.org/t/processing-to-arduino-serial-library-example/11143/5):
>
> I modified the existing “SimpleWrite” example to: save and check for the state of mouseOverRect() print state to console only writes serial data once a delay() to wait for Arduino to reset once connected to it; in my case, it is an Arduino Mega 2560 R3. I kept the spirit of the original example intact and left it as a “Simple Write” program. My edit of “SimpleWrite” example so it only sends data once: /\*\* \* Simple Write. \* \* Check if the mouse is over a rectangle and writes the status …

The Arduino code is in the examples in the Processing IDE and here:

> <https://github.com/processing/processing/tree/master/java/libraries/serial/examples>
>
> //github.com/processing/processing/tree/master/java/libraries/serial/examples

This came in handy when I was setting this up:

> **[SerialPassthrough | Arduino Documentation](https://docs.arduino.cc/built-in-examples/communication/SerialPassthrough)**
>
> Demonstrates how to virtually connect Serial and Serial1.

`:)`

---

_[View the full topic](https://discourse.processing.org/t/solved-problems-sending-data-from-processing-to-arduino-through-serial-port/20138)._
