I am running Processing to interact w Arduino using code from "Exploring Arduino"

I run Listing 6-6. in the Processing IDE. But the IDE keeps reporting "Error opening serial port COM3: Port not found". I think its wants me to put the serial library into the same directory with the code directory. But I dont know how to find the serial library, to copy it to there. Please help

Answers

  • Please provide your code and any relevant links.

    Kf

  • The code segments below come from Exploring Arduino Chapter 6. The Aruino code is Listing 6-6, and the processing code is listing 6-7. I run Listing 6-7. in the Processing IDE. But the IDE keeps reporting "Error opening serial port COM3: Port not found". I think its wants me to put the serial library into the same directory with the code directory. But I dont know how to find the serial library, to copy it to there. Please help, I am brand new to Processing.

    Here is my Arduino code

    
        //Sending POT value to the computer
        const int POTpin=0;  //POT on analog pin 0
        int val;  //For holding the measured pot value
        
        void setup() 
        {  // put your setup code here, to run once:
        Serial.begin(9600);  //Start the serial I/O on COM 3
        }
        
        void loop() 
        {  // put your main code here, to run repeatedly:
        
          val=map(analogRead(POTpin),0,1023,0,255);  //Read and MAP the A/D value to the color range
          Serial.println(val);                       //Send val to computer to be read by processor
          delay(100);                                 //delay keeps from overruning the buffer at the computer
          
        
        }
    
    
        //Processing Sketch to read Arduino POT value and Change color on screen
        //import and initialize serial port library
        import processing.serial,*;
        Serial port;
        
        float brightness = 0;  //for holding the value from the pot
        
        void setup()
        {
          size(500,500);                          //window size
          port = new Serial(this, "COM3", 9600);  //set up serial
          port.bufferUntil('\n');                 //set up port to read until newline
          
        }
        
        void draw ()
        {
          background(0,0,brightness);   //update the color in the window
        }
        
        void serialEvent (Serial port)
        {
          brightness = float(port.readStringUntil('\n'));  //get a value from arduino
        }
        
  • "Error opening serial port COM3: Port not found"

    @Rocketman have you run an arduino sketch before? If you open the Arduino IDE (As described in arduino.cc website), it should tell you what com your arduino is.

    I am going to guess your problem is that you are trying to open the wrong serial port assigned to your arduino. Are you sure you are opening the right port. One easy way to check is to run the next code twice. The first time, ensure your arduino is not connected. Check what ports are listed. Then, connect your arduino and run the code again. If you compare the listed ports, you will see the extra port in the second call corresponds to the serial port assigned to your arduino.

    Serial port;
    void setup(){
      println(port.list());
      exit();
    }
    

    N.B. If the above code works, then your serial library is properly installed and you do not have to move it or make any changes

    I suggest you check any quick start guide working with arduinos online. They will do a better job desribing how to setup your arduino unit. For you, it is important that you know what serial port is being assigned to your device before you try talking to it.

    Kf

  • kfrajer: The Arduino IDE can show print coming in over the USB from the Arduino, and it shows up on COM3. I wanted to use Processing so that I can do graphics with the data reported. So I am sure its COM3 because of that.

  • Are you running the serial monitor concurrently with your Processing sketch?

    If you can see data through your serial monitor, you should be able to get data in your sketch. However, make sure you close your serial monitor as it occupies the com port.

    Kf

Sign In or Register to comment.