Let's Make Robots!

Trouble with arduino/processing

I've been trying to teach myself Arduino and Processing, and I've been hitting a few problems. I had a previous post Here, but it was getting a bit crowded with code, so I thought I'd start a new post.

I've been trying to send an integer value from Processing to Arduino via serial, to set the brightness of the on-board LED. The arduino sketch works, and I've tested it with the serial monitor. When I try to control it with my Processing sketch, though, it only adjusts between 47-60 rather than the full range of 0-100. I'm using the ControlP5 and serial libraries in processing, and the softPWM library on the arduino to PWM the onboard LED.



#include <SoftPWM.h>
#include <SoftPWM_timer.h>
int LED = 13;
int dim = 0;
void setup() {
void loop() {
  while (Serial.available() > 0) {
    int dim = Serial.parseInt();
    if (Serial.read() == '\n') {

Processing (The reason the value is called servo is because I'd intended to control a servo, but didn't get round to it);

import processing.serial.*;
Serial myPort;
import controlP5.*;
ControlP5 cp5;
int Servo = 0;
int out = 0;
Knob controller;
void setup() {
  size (200,200);
  myPort = new Serial(this, "COM6", 2400);
  cp5 = new ControlP5(this);
  controller = cp5.addKnob("Servo")

void draw() {

Any Ideas?

PS; can the arduino provide MIDI over USB?


Thanks in advance.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I would have to say the 47,60 in the range variable is something to look at, but it should be noted that you are sending an INT via serial and it does not look like you are taking it apart (into bytes) first. If you are only using a 0-100 range (or even a 0-255 range), I would use a byte for your "servo" variable instead.

Thans for the reply. I've given using byte instead of int a shot, but had no luck. The 47,60 range variable was origeonally 0,100, but I changed it to see how smooth it was within those values. It's just the range for the knob. I've also tried changing the port settings (parity etc.), but it didn't help, so I set it back. Do you have any idea how to monitor serial activity? I was just wondering if it's possible to use a bit of software to compare what the arduino serial terminal and the processing sketch were sending, so I could have a better guess as to what's wrong.