0

I have a problem where I kwow that my bluetooth module (HC-05) is connected to a processing sketch, but nothing ever gets sent from the processing sketch,why?

No error messages but the info never gets sent over because I never see it in Arduino, where it would be printed to the Serial Monitor.

Full Processing Code:

import processing.serial.*;
import controlP5.*;

Serial myPort;
ControlP5 cp5;

int slider1 = 0;
int slider2 = 0;
int slider3 = 0;

void setup() {


  size(800, 800);
  cp5 = new ControlP5(this);
  PFont roboto = createFont("Roboto-Bold.ttf", 1, true);
  ControlFont font = new ControlFont(roboto, 28);
  Controller Aslider1 = cp5.addSlider("slider1")
    .setPosition(85, 100)
    .setCaptionLabel("Red")
    .setRange(0, 255)
    .setWidth(191)
    .setHeight(50);
  cp5.getController("slider1").getValueLabel().setFont(font).align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
  cp5.getController("slider1").getCaptionLabel().setFont(font).align(ControlP5.RIGHT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);

  Controller Aslider2 = cp5.addSlider("slider2")
    .setPosition(301, 100)
    .setCaptionLabel("Green")
    .setRange(0, 255)
    .setWidth(191)
    .setHeight(50);
  cp5.getController("slider2").getValueLabel().setFont(font).align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
  cp5.getController("slider2").getCaptionLabel().setFont(font).align(ControlP5.RIGHT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);

  Controller Aslider3 = cp5.addSlider("slider3")
    .setPosition(517, 100)
    .setCaptionLabel("Blue")
    .setRange(0, 255)
    .setWidth(191)
    .setHeight(50);
  cp5.getController("slider3").getValueLabel().setFont(font).align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
  cp5.getController("slider3").getCaptionLabel().setFont(font).align(ControlP5.RIGHT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);


  myPort = new Serial(this, "COM5", 9600);
}


void draw() {
  background(255, 100, 100);

  fill(255);
  stroke(1);
  rectMode(CENTER);
  rect(width/2, 350, 200, 75);

  fill(0);
  textSize(32);
  text("Send", width/2 - textWidth("Send") / 2, 350 + 10);

  if (mouseX > width/2 - 100 && mouseX < width/2 + 100 && mouseY > 350 - 75/2 && mouseY < 350 + 75/2) {
    if (mousePressed) {
      fill(100);
      stroke(1);
      rectMode(CENTER);
      rect(width/2, 350, 200, 75);

      fill(0);
      textSize(32);
      text("Send", width/2 - textWidth("Send") / 2, 350 + 10);
    } else {
      fill(170);
      stroke(1);
      rectMode(CENTER);
      rect(width/2, 350, 200, 75);

      fill(0);
      textSize(32);
      text("Send", width/2 - textWidth("Send") / 2, 350 + 10);
    }
  }
}

void mouseReleased() {
  if (mouseX > width/2 - 100 && mouseX < width/2 + 100 && mouseY > 350 - 75/2 && mouseY < 350 + 75/2) {
    fill(100);
    stroke(1);
    rectMode(CENTER);
    rect(width/2, 350, 200, 75);

    fill(0);
    textSize(32);
    text("Send", width/2 - textWidth("Send") / 2, 350 + 10);

    println(hex(color(int(slider1), int(slider2), int(slider3))).toString().substring(2));
    myPort.write(hex(color(int(slider1), int(slider2), int(slider3))).toString().substring(2));
    myPort.clear();
  }
}

Full Arduino Code:

#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>

const int PIN = 6;
const int NUMPIXELS = 30;

const byte rxPin = 2;
const byte txPin = 3;
SoftwareSerial mySerial (rxPin, txPin);

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

unsigned long currentMillis;
unsigned long loopMillis;
unsigned long waitMillis;
int interval = 100;
int waitInterval = 0;
int redBrightness = 0;
int greenBrightness = 0;
int blueBrightness = 0;
bool wait = false;
bool goToRed = true;
bool goToOrange = false;
bool goToYellow = false;
bool goToGreen = false;
bool goToAqua = false;
bool goToPurple = false;

String hexValue;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  mySerial.begin(9600);
  pixels.begin();
  pixels.show();
}

void loop() {

  if (mySerial.available() > 0) {
    hexValue = mySerial.read();
    Serial.println(hexValue);
    if (hexValue != "shiftN" || hexValue != "shiftY") {
      shiftMode = false;
      // value is a hex
      redBrightness = hexValue.substring(0, 2).toInt();
      greenBrightness = hexValue.substring(2, 4).toInt();
      greenBrightness = hexValue.substring(4, 6).toInt();
    } else {
      if (hexValue = "shiftY") {
        shiftMode = true;
      } else {
        shiftMode = false;
      }
    }
  }

  pixels.show();

  setColor(redBrightness, greenBrightness, blueBrightness);

}

void setColor(int red, int green, int blue) {
  for (int i = 0; i < NUMPIXELS; i++) {
    pixels.setPixelColor(i, red, green, blue);
  }
}

Thanks for the help, cheers!

https://discourse.processing.org/t/nothing-gets-sent-to-arduino-from-processing/13654

https://stackoverflow.com/posts/57679763/edit

  • how do you know that the module is connected to Processing? – jsotola Aug 27 at 23:57
  • @jsotal it blinks twice and then repeats – BeastCoder2 Aug 28 at 10:52
0

Part of the problem is with the Arduino sketch where you parse the "input string" into integer variables. There are 2 greenBrightness variables in the loop(), where you probably wanted a blueBrightness variable.

I was able to get the processing sketch to work after hard coding in the correct serial port for my OS, but was stopped at the font creation. Perhaps you could use a try catch block when trying to create the custom font (my computer does not have it installed). If the try block fails, something like "Georgia" or "Helvetica" font would do PFont roboto = createFont("Georgia", 1, true);.

I'm not quite sure how you have the SoftwareSerial implemented. Are you using a second USB to Serial converter? To bypass this, I connected a I2C LCD to the Arduino Uno to display the data received and just used the hardware serial to grab the data from Processing.

Here is where things got interesting. When I set the 3 sliders in the Processing app to 0, the LCD printed 048 for each of the "color variables", plus a little bit of garbage data.

I don't have a definitive answer as to why the data is corrupted, but that is the area of the Arduino code to look at.

  • You have to have the Roboto-Bold.ttf in a data folder named "data" in the directory of the program. I am using an HC-05 as stated above with bluetooth – BeastCoder2 Aug 28 at 10:54
  • it works perfectly fine for me when I do 0 0 0 for the values, it just shows 000000 – BeastCoder2 Aug 28 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.