Struggling with Arduino and Processing

Hi! Me and my dad are both new to Arduino and coding in general and we're trying to learn. We're using a book called Make: Getting Started With Arduino (4th Edition) and we're trying to do a project from it that ends up creating a cool multi-colored lamp. However, we keep getting the error message "The type Serial is ambiguous" for the line "Serial port;" in Processing. Our Processing version is 4.5.7. We've copied the code exactly from the book (we've checked and triple checked) and it's not working. It's super frustrating and I'd love some help figuring this out.

Processing in not in my wheelhouse, but I vaguely recall that there was a change made (engineers and software types love to change things) that caused that. So now any material written prior to that change hiccups. Try changing it to processing.serial.Serial port; and see if that helps.

when asking a question about an error you should

  • provide a copy of the error
  • post the code

people can only guess without seeing both

Nothing wrong with learning Processing of course and please forgive me for interjecting, but I am curious as to why you chose to go down the Processing route over using the Arduino IDE? Was this a conscious decision or simply because you happened to find an start with that book?

@BitSeeker

I think that the project involves an Arduino and a program for the PC written in Processing.

I've now done a complete install of Processing 4.5.7 on my Win11 system (I have older versions) and have not encountered the error that you get with the below sketch

// Example by Tom Igoe

import processing.serial.*;

// The serial port:
Serial myPort;       

// List all the available serial ports:
printArray(Serial.list());

// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[0], 9600);
  
// Send a capital A out the serial port:
myPort.write(65);

The above is the example sketch from https://processing.org/reference/libraries/serial/Serial.html. The full reference for Processing's Serial can be found here: https://processing.org/reference/libraries/serial/index.html

I did some diffing on the Processing forum and found two possible solutions. The root cause is a conflict that two "libraries" contain a definition for the Serial class

  1. processing.serial
  2. java.io

I've created a stripped down version of a code related to the networked lamp that gives the same error

import processing.serial.*;
import java.net.*;
import java.io.*;
import java.util.*;

Serial port;

There are two possible solutions (not tested but both options get rid of the The type Serial is ambiguous error)

  1. Remove the import of the java,io.*; see Type Serial is ambiguous - #4 by glv - Electronics (Arduino, etc.) - Processing Community Forum
  2. Change the Serial port; to processing.serial.Serial port;; see Help with code in the book Make: Getting Started with Arduino - #14 by svan - Electronics (Arduino, etc.) - Processing Community Forum. This will make it clear to the PDE that you want to use a specific Serial class.

I've moved your topic to a forum category specific to communication between PC and Arduino.

We have found that book/magazine to contain errors due to aging, circa 2012.

Is your project the "peace, love, Arduino" project?

If so, this might help get you through... The Arduino Networked Lamp

Yes, that is understood. Looking at the editions of the book, the first one was released around 2012 as @xfpd points out, but the 4th edition appears to have been released much later around 2022. Although that is still 4 years ago, I had wondered whether Processing is worth pursuing as an alternative Arduino development environment and whether its developers consider it as such. I am happy with the Arduino IDE as the "workhorse" and even with Vscode at a push, but also curious enough to explore other options.

From above comments it is evident that Processing has changed somewhat (hopefully not quite as much as with the Python 2 vs 3 fiasco) and the information in the book is out of date and needs revising. Therefore, depending on the reason for going down that route, for future projects, the OP(s) might be better served following a different, more up-to-date tutorial that refers to the currently preferred programming environment that is the Arduino IDE. The IDE itself also contains multiple examples that might better serve to familiarize them with Arduino development. However, everyone's preferences are different and I don't want to impose if the object was specifically to learn Processing. I am therefore curious whether the project was chosen simply because it was in the book, or whether the book was chosen specifically to learn Progress.

The Processing IDE is something completely different from Arduino IDE, not an alternative. Processing is for creating programs that run on a PC. Arduino IDE is for creating programs that run on a microcontroller.

They can certainly be used symbiotically for projects that involve a PC and microcontroller working in concert. I believe an expectation that such a practice would be common was actually a factor in basing the "Arduino language" on the Processing language during the origins of the Arduino project (actually Wiring at that time).

Of course with the introduction of the UNO Q and VENTUNO Q boards, you might even run a Processing script on the MPU and an Arduino sketch on the MCU of the same board.

Try these two lines for "Serial port;" (you can see what it was in the comment beside the line of code... again, assuming Arduino Networked Lamp, as in Post #8)

import processing.serial.*;
Serial port;  // full class: processing.serial.Serial port;

Warning: you will get a Processing error (red line at the bottom of the code window) stating, "ArrayIndexOutOfBounds" (et c... all mashed together) if your Arduino/USB is not connected to the COM port. The error means the "array" is your "array of com ports".

The order of starting these two sketches (Arduino and Processing) is:

  1. Upload the sketch into the Arduino (code starts running)
  2. "Run" the Processing code.

Starting the Processing sketch before uploading the Arduino sketch will cause errors when trying to upload the sketch to Arduino/

Thanks for the clarification. Sounds like Processing might be used in very much the same way that Python is used to interact with the serial port of an Arduino that already has a sketch running on it. Of course Processing has its own unique features.

I did find this project that I might begin my exploration of Processing with.

So many... Examples / Processing.org

Yes, a lot of examples there. For the fun of it, once I finish what I am currently working on, I though I might even have a go at modifying the Network Lamp project you linked to see whether I can make it work with one of the old ShiftBrite LED modules I have lying around.

Anyway, I hope the OP has managed to sort their problem with the serial port.