Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • Etch-a-Sketch DrawBot software setup

    I'll start by saying I'm very new to processing, so please feel free to point out even the most obvious of error in my logic ;)

    I've been working on a DrawBot based on an etch-a-sketch (mostly to amuse the little fella) and looking for suitable software for image to gcode conversion. I came across the amazing death to sharpies project which I believe uses Drawbot_image_to_gcode_v2 which I think (?) is based on processing for its image conversion.

    Question: I'm looking for some guidance on how best to installed / compiled / executed Scott-Cooper's code - Drawbot_image_to_gcode_v2. It also seems to have several dependancies or libraries any guidance on tracking these down would be appreciated. I guess I'm looking for Processing 101 / Drawbot 101

    Hardware & Software 1 x Etch-a-sketch 2 x Nema17 Stepper motors 2 x A4988 Stepper Motor Driver 1 x Arduino Uno 1 x Protoneer cnc shield v3 1 x 24v Power Supply 1 x Mac streaming gcode to arduino

    GRBL firmware

    Thanks for reading, any tips, trick, guides or pointers would be appreciated!

  • ustepper motor control over serial

    Hi Guys, looking for some help. I got a ustepper running arduino code.

    my mission is to create a linear rail running off a txtbox and btn in processing. set distance click ok, slide moves to that position.

    I have been trying for 2weeks and am now asking for help, it sounds simple but im pulling my hair out. does anyone have sample code for this?

    attached are the parts i'm having trouble with. I thank you all well in advance for taking the time to look at my train wreck.

    //arduino //other code outside this sample loops through temp sensor ect and prints to txtbox's as a read out

    void readinput(){``
    
    if (Serial.available() > 0) {
        // get incoming byte:
        inByte = Serial.readString();
    
        if(inByte == "red"){
    
    stepper.moveSteps(200, CCW, SOFT);
    
        }
    
    if(inByte == "move"){
    
    while (Serial.available() <= 0) {
    Serial.println('A');
    }
    
    
    inByte = Serial.readString();
    //Serial.println(inByte.toInt());
    stepper.moveSteps(inByte.toInt(), CCW, SOFT);
    //Serial.flush();
    //Serial.println('A');
    }
    }
    }
    
    
    
    
    
    
    
    //processing code
    
    public void button4_click1(GButton source, GEvent event) { //_CODE_:button4:783421:
    
    myport.write("move");
    //53.5 steps per mm
    
    while (myport.available() <= 0){
     // println("fffffffffffffff");
       println(myport.read());
    }
    double aa = Double.parseDouble(textfield6.getText());
    double ans = aa*53.5;
    int aws = (int) ans;
    //println(ans);
    println(aws);
    
    println(myport.read());
    
    
    myport.write(Integer.toString(aws));
    }
    
  • run up to 10 stepper motors via arduino?

    @lumicon -- if you search this forum for "stepper"

    ...there are recent discussions of projects with 2 / 4 / 6 motors.

  • run up to 10 stepper motors via arduino?

    hi, i'm thinking of realizing a kinetic sculpture, where i would need like 10 stepper motors which would simulate a 2d noise. is there a way to drive so many motors via arduino out of one processing script (simple noise for structure)?

  • Raspberry pi with processing outputing X Y data to arduino

    Right OK, I fear I'm rapidly out of my depth so grateful for any help!

    I'm running a processing sketch on a pi 3 attached to a touch screen. As the screen is touched its drawing a line with the finger. Whilst doing that its printing the X , Y coordinates to the console in processing.

    What i'm trying to do is get these coordinates to the arduino. The arduino has an uploaded HEX file onto the onboard chip. These are controlling 2 steppers. So if you have the arduino IDE running you type X10 into the serial monitor and in drives the stepper. So, the arduino is tied up with grbl so I can't run a sketch to look for data or act on data being sent.

    I some how need to get the X Y data to the arduino. Is the best way through a USB cable? I've followed this useful link to set up the serial arduino command setup

    (http://scruss.com/blog/2014/01/07/processing-2-1-oracle-java-raspberry-pi-serial-arduino-☺/)

    and have data going from processing to arduino

    this works as a test flashing the arduino light on and off

    import processing.serial.*;
    import cc.arduino.*;
    Arduino arduino;
    int ledPin = 13;
    
    void setup()
    {
      println(Arduino.list());
      arduino = new Arduino(this, Arduino.list()[0], 9600);
      arduino.pinMode(ledPin, Arduino.OUTPUT);
    }
    
    void draw()
    {
      arduino.digitalWrite(ledPin, Arduino.HIGH);
      delay(1000);
      arduino.digitalWrite(ledPin, Arduino.LOW);
      delay(1000);
    }
    

    this is also working with my attempt to get X10 to the arduino grbl shield but no X10 going to arduino. mouse released in processing square LED on arduino blinks.

    import processing.serial.*;
    import cc.arduino.*;
    Arduino arduino;
    
    void setup()
    {
      size (200,200);
      println(Arduino.list());
      arduino = new Arduino(this, Arduino.list()[0],9600);
    }
    
    void draw() {
      background(100);
    }
    void mouseReleased(){
      arduino.digitalWrite('X', 10);
    }
    

    heres the code for the processing sketch do far it works but no data going to the serial of the arduino, should I be using digitalwrite to write the data into the arduino serial monitor, should i not be using USB but rather TX RX?

    import processing.serial.*;
    import cc.arduino.*;
    Arduino arduino;
    
    void setup()
    {
      size (200,200);
      println(Arduino.list());
      arduino = new Arduino(this, Arduino.list()[0],9600);
    }
    void setup() 
    {
      size(200,200); //make our canvas 200 x 200 pixels big
      String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
      myPort = new Serial(this, portName, 9600);
    }
    
    void draw() {
      stroke(255);
      if (mousePressed == true) {
        line(mouseX, mouseY, pmouseX, pmouseY);
      }
    }
    void mousePressed ()
    {
        println("PRESSED x:" +mouseX + " y:" + mouseY);
    }
    void mouseDragged ()
    {
      println("G01 x" +mouseX + " y" + mouseY + " F100");
    }
    

    Thankyou in advance for any help. Loving the whole coding hardware... but struggling with the depth of knowledge required and coding logic!

  • I have a GUI that I need someone to turn into an Android APP.

    I'm not a coder by any means, so I hired someone to built a GUI in Processing (of course), and now I need to hire someone to turn it into and Android App.

    I'm using an Arduino Rev 3, Easy Driver, Nema 17 stepper motor.

  • How to get wind data from an api and then use the data to run a motor

    Hello,

    I am a visual arts student with very minimal experience in processing. I am working on a project at which i am stuck very bad. I want to get data from weather api (wind) and then use the data to drive a stepper motor using arduino. Can anyone please help me.

  • How to develop a star trecking system for my telescope?

    Hi, i’m Alex and I come from Germany. well, my hobby is astronomy and I will develop an automaticly star tracking system.

    Which parts do I have now: 1x Arduino UNO 2x Stepper motor 1x Webcam 1x Telescope 1x Laptop

    My first setep with processing was 4 weeks ago. Currently, I can conect the arduino with processing and processing visualized the value from arduino. I can also conect a webcam with processing.

    The next step will be: How to realize a start trackin system?

    My ideas are: The Webcam view in the sky, I pick out the brightest star from the display which is suitable for tracking and the Arduino will controll the stepper motor for X and Y axis from the telescope . I have never done this bevore, so... I hope you can help/support me ☺ . I apologize for my bad english and I hope you understand me. How to start best?

    Best regards from Germany ☺

  • i have six objects, i need to choose a starting one by clicking a box then an ending one by clicking

    another box. depending which way i choose i turn a stepper motor cw or ccw. I am way over my head with programing this one, is there anyone who wants to help write this. Let me know.

  • Creating a Class with Firmata for Arduino

    I'm creating a radar simulation, and want to send data from Processing to an Arduino to control 4 small stepper motors to display range and bearing on 4 dials. Firmata seems like a good solution for this.

    Would like to create a Class "MOTOR" and instantiate each of the motors in the main sketch. I've successfully created a number of simple classes before, but am unclear on how/where to place the special libraries that need to be imported for Firmata. Also not sure where this should be placed: arduino = new Arduino(this, Arduino.list()[5], 115200);

    The general question is: When creating a Class which uses specific libraries - where should the libraries be imported - in the 'main' sketch or in the class?

  • unexpected char: 'i' have searched to no avail

    Thank you!

    #include <Time.h> 
    #include <Wire.h>  
    #include <WProgram.h>
    #include <TimeAlarms.h>
    #include <DS1307RTC.h> 
    
    ///////// Declaration of Pin Variables ////////
    int DIR = 13;         // PIN 13 = DIR
    int STEP = 12;        // PIN 12 = STEP
    int MS1 = 7;          // PIN 7 = MS
    int MS2 = 6;          // PIN 6 = MS2
    int SLEEP = 5;        // PIN 5 = SLP
    
    // Clock SDA to analog pin 4, SCL to analog pin 5
    
    #define DEBUG                         // Compile serial monitor clock display
    #define SETCLOCK                      // Compile clock setup code
    #define DS1307_I2C_ADDRESS 0x68       // Seven bit address
    #define MAXLINE 10
    #define Mode12 1
    #define Mode24 0
    #define AM 0
    #define PM 1
    
    static char *dayname[] =
    { 
          "Sunday",
          "Monday",    
          "Tuesday",  
          "Wednesday",  
          "Thursday",
          "Friday",
          "Saturday"
    };
    
    ////////// Pin activation via "pinMode" & initializing daily alarms ///////////
    void setup() 
    {
          Serial.begin(9600); 
          Wire.begin();
    
          pinMode(DIR, OUTPUT);                       // Set pin 13 to output
          pinMode(STEP, OUTPUT);                      // Set pin 12 to output
          pinMode(MS1, OUTPUT);                       // Set pin 7 to output
          pinMode(MS2, OUTPUT);                       // Set pin 6 to output
          pinMode(SLEEP, OUTPUT);                     // Set pin 5 to output  
    
          digitalWrite(SLEEP, LOW);                   // Switches off power to the motor initially
    
          Alarm.alarmRepeat(20,0,0,OpenShutter);      // Open shutter at 8:00 PM every day      
          Alarm.alarmRepeat(06,0,0,CloseShutter);     // Close shutter at 6:00 AM every day
    
          Serial.println("Initailizing shutter system startup...");
          Serial.println("- Ensure that the shutter is completely covering the lens.");
          Serial.println("- After being prompted to set the time:");
          Serial.println("    - The shutter will momentarily open and close to confirm its proper motion.");
          Serial.println("    - The clock output will be displayed in the serial window.");
          Serial.println("    - The shutter will open at 8:00 PM (20:00) and close at 6:00 AM (06:00) daily.");
    
          #ifdef SETCLOCK
                char ans[1];
                int serbytes=0;
                Serial.println("Type 'y' and press 'return' to set the clock. Type anything else and press 'return' to skip this process");
                serbytes = getSerStrWait(ans, 1, 10);
                if (strcmp(ans, "y") == 0) 
                {
                    setClock();
                }  
          #endif 
    
         setSyncProvider(RTC.get);   // The function to get time from the RTC
         if(timeStatus()!= timeSet) 
         {  
                Serial.println("Initializing... Unable to sync with the RTC! Check the RTC battery or the RTC wire connections"); 
         }
         else
         {
                Serial.println("Initializing... RTC has set the shutter system time");
         }
    }
    
    /////////////////////////////// Clock stuff //////////////////////////////////
    
    void loop()
    {
        byte second, minute, hour, dayOfWeek, dayOfMonth, month, year, ampm;
    
        getClock(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year, &ampm);
    
        #ifdef DEBUG
              leadzero(hour);
              Serial.print(hour, DEC);
              Serial.print(":");
              leadzero(minute);
              Serial.print(minute, DEC);
              Serial.print(":");
              leadzero(second);
              Serial.print(second, DEC); 
              if (ampm != ' ')                                    //Not space
              {                       
                    Serial.print(" ");
                    Serial.print(ampm);
                    Serial.print("M");
              }  
              Serial.print(" ");
              leadzero(month);
              Serial.print(month, DEC);
              Serial.print("/");
              leadzero(dayOfMonth);
              Serial.print(dayOfMonth, DEC);
              Serial.print("/");
              leadzero(year);
              Serial.print(year, DEC);
              Serial.print(" ");
              Serial.println(dayname[dayOfWeek-1]);
        #endif
    
        Alarm.delay(60000);
    }
    
    void leadzero(byte val) 
    {
        if (val < 10) 
        {
              Serial.print("0");
        }  
    }
    
    #ifdef SETCLOCK
    void setClock() 
    {
         // Prompt for time settings
         byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
         byte mode = 0;
         byte ampm = 0;
         char ans[1];
         char dig2[3];
         int serbytes=0;
    
         Serial.println("Enter 2 dig year");
         serbytes = getSerStr(dig2, 2);
         year = atoi(dig2);
         Serial.println("Enter 2 dig month");
         serbytes = getSerStr(dig2, 2);
         month = atoi(dig2);
         Serial.println("Enter 2 dig day of month (1-31)");
         serbytes = getSerStr(dig2, 2);
         dayOfMonth = atoi(dig2);
    
         Serial.println("Enter day of week, where: 1=Sunday 2=Monday 3=Tuesday 4=Wednesday 5=Thursday 6=Friday 7=Saturday");
         serbytes = getSerStr(dig2, 1);
         dayOfWeek = atoi(dig2);
    
         Serial.println("Enter clock mode: 12 or 24");
         serbytes = getSerStr(dig2, 2);
         if (strcmp(dig2, "12") == 0) 
         {
             mode = Mode12;  
             Serial.println("Enter 'a' or 'p' for AM or PM");
             serbytes = getSerStr(ans, 1);
             if (strcmp(ans, "p") == 0) 
             {
                 ampm = PM;  
             }
         }  
         Serial.print("Enter 2 dig hour ");
         if (mode == Mode12) 
         {
             Serial.println("(1-12)");
         }
         else
         {
             Serial.println("(0-23)");
         }  
         serbytes = getSerStr(dig2, 2);
         hour = decToBcd(atoi(dig2));
    
         Serial.println("Enter 2 dig minute");
         serbytes = getSerStr(dig2, 2);
         minute = atoi(dig2);
         second = 0;
         if (mode == Mode12) 
         {
             bitSet(hour,  6);
             if (ampm == PM) 
             {
                  bitSet(hour, 5);
             }  
         }  
         Wire.beginTransmission(DS1307_I2C_ADDRESS);
         Wire.send(0);
         Wire.send(decToBcd(second));                           // 0 to bit 7 starts the clock
         Wire.send(decToBcd(minute));
         Wire.send(hour);                                       // Already formatted with bits 6 and 5
         Wire.send(decToBcd(dayOfWeek));
         Wire.send(decToBcd(dayOfMonth));
         Wire.send(decToBcd(month));
         Wire.send(decToBcd(year));
         Wire.endTransmission();
    }
    #endif
    
    // Gets the date and time from the DS1307
    void getClock(byte *second,
                  byte *minute,
                  byte *hour,
                  byte *dayOfWeek,
                  byte *dayOfMonth,
                  byte *month,
                  byte *year,
                  byte *ampm)
    {
          byte work;
          byte mode;          // 12 or 24 hour
          byte ap_ind;        // AM or PM indicator
    
          // Reset the register pointer
          Wire.beginTransmission(DS1307_I2C_ADDRESS);
          Wire.send(0);
          Wire.endTransmission();
    
          Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
    
          // A few of these need masks because certain bits are control bits
          *second     = bcdToDec(Wire.receive() & 0x7f);        // Mask CH bit (bit 7)
          *minute     = bcdToDec(Wire.receive());
    
          // *hour = bcdToDec(Wire.receive());
          work = Wire.receive();                                // Get hour byte
          mode =  bitRead(work, 6);                             // If bit  6  set,  running 12 hour mode
          if (mode == Mode12) 
          {
                ap_ind = bitRead(work, 5);                      // If bit 5 set,  time is PM
                *hour = bcdToDec(work & 0x1f);                  // Mask bits 5 thru 7 for 12 hour clock
                if (ap_ind == PM) 
                {
                      *ampm = 'P';
                }
                else
                {
                      *ampm = 'A';
                }  
          }
          else
          {  
                *hour = bcdToDec(work & 0x3f);                   // Mask bits 6 and 7 for 24 hour clock
                *ampm = ' ';  
          }  
    
          *dayOfWeek  = bcdToDec(Wire.receive());
          *dayOfMonth = bcdToDec(Wire.receive());
          *month      = bcdToDec(Wire.receive());
          *year       = bcdToDec(Wire.receive());
    }
    
    #ifdef SETCLOCK
    int getSerStr(char line[], int lim) 
    {
          int bytesread=0;
          int val=0;
          Serial.flush();  
          while(bytesread<lim) 
          {              
                if( Serial.available() > 0) 
                {
                      val = Serial.read();
                      if((val == 10) || (val == 13) || (val == '*')) 
                      {        
                            break;                              // Stop reading
                      }
                      line[bytesread] = val;                    // Add the digit          
                      bytesread++;                              // Ready to read next character  
                }
           }
           line[bytesread] = '\0';                              // Terminate string  
           return(bytesread);
    }
    
    int getSerStrWait(char line[], int lim, int waitsecs) 
    {
          int bytesread=0;
          int val=0;
          unsigned long waitms = 1000 * waitsecs;
          unsigned long start = millis();
          Serial.flush();  
          while(bytesread<lim) 
          {              
                if( Serial.available() > 0) 
                {
                      val = Serial.read();
                      if((val == 10) || (val == 13) || (val == '*')) 
                      {        
                            break;                              // Stop reading
                      }
                      line[bytesread] = val;                    // Add the digit          
                      bytesread++;                              // Ready to read next character  
                }
                if (millis() - start > waitms) 
                {
                      Serial.flush();
                      line[0] = '\0';
                      return(0);
                }  
           }
           line[bytesread] = '\0';                              //Terminate string  
           return(bytesread);
    }
    #endif
    
    // BCD to decimal conversion: decVal =(bcdVal.NIB1 * 10) + bcdVal.NIB0
    // Decimal to BCD conversion: bcdVal = (decVal / 10 <<4) + bcdVal // 10
    
    // Convert normal decimal numbers to binary coded decimal
    byte decToBcd(byte val)
    {
          return ( (val/10*16) + (val%10) );
    }
    
    // Convert binary coded decimal to normal decimal numbers
    byte bcdToDec(byte val)
    {
          return ( (val/16*10) + (val%16) );
    }
    
    /////////////////////////////////////// FORWARDS ROTATION //////////////////////////////////////////////
    
    void CloseShutter()
    {
          Serial.println("AWAKE!! CLOSING!!!");   
          {
              digitalWrite(DIR, HIGH);          // Set the direction change LOW to HIGH to go in opposite direction
              digitalWrite(MS1, LOW);           // Set state of MS1 
              digitalWrite(MS2, LOW);           // Set state of MS2 
              digitalWrite(SLEEP, HIGH);        // Set the Sleep mode to AWAKE (Allow power to stepper motor).
          }  
    
          int i = 0;                            // Set the counter variable.  
          while(i<(100))                        // Iterate for appropriate amount of steps
          {
               digitalWrite(STEP, LOW);         // This LOW to HIGH change is what creates the..
               digitalWrite(STEP, HIGH);        // .."Rising Edge" so the easydriver knows to when to step.
               delayMicroseconds(14400);         // This delay time determines the speed of the stepper motor.                                            
               i++;                     
          }                          
    
          delay(500);  
          digitalWrite(SLEEP, LOW);             // Switch off the power to stepper  
          Serial.print("SLEEPING...");
          delay(250);
          Serial.print(" zzz ");
          delay(250);
          Serial.print("zzz ");
          delay(250);
          Serial.print("zzz ");
          Serial.println(" ");
    }
    
    /////////////////////////////////////// OPPOSITE ROTATION /////////////////////////////////////////////////  
    
    void OpenShutter()
    {
          Serial.println("AWAKE!! OPENING!!!");
    
          {
              digitalWrite(DIR, LOW);           // Set the direction change LOW to HIGH to go in opposite direction
              digitalWrite(MS1, LOW);           // Set state of MS1 based on the returned value from the MS1_MODE() switch statement.
              digitalWrite(MS2, LOW);           // Set state of MS2 based on the returned value from the MS2_MODE() switch statement.
              digitalWrite(SLEEP, HIGH);        // Set the Sleep mode to AWAKE. 
          }
    
          int j = 0;                            // Set the counter variable.    
          while(j<(100))                        // Iterate for 200, then 400, then 800, then 1600 steps. Then reset to 200 and start again.
    
          {
              digitalWrite(STEP, LOW);          // This LOW to HIGH change is what creates the..
              digitalWrite(STEP, HIGH);         // .."Rising Edge" so the easydriver knows to when to step.
              delayMicroseconds(14400);          // This delay time determines the speed of the stepper motor. Delay shortens from 1600 to 800 to 400 to 200 then resets                                              
              j++;                     
          }                             
    
          delay(500);  
          digitalWrite(SLEEP, LOW);             // Switch off the power to stepper  
          Serial.print("SLEEPING...");
          delay(250);
          Serial.print(" zzz ");
          delay(250);
          Serial.print("zzz ");
          delay(250);
          Serial.print("zzz ");
          Serial.println(" ");
    }
    
  • unexpected char: 'i' have searched to no avail

    Hi Everyone,

    I am extremely new to Processing and honestly I am not that great of a coder. Currently, my goal is to revamp a preexisting project which involves a timed shutter for a camera. I am using Arduino in conjunction with Processing for this. The overall goal is to set time alarms in Arduino so that the Shutter (stepper motor) opens/closes (moves/rotates) at two specific times each day. For this reason, I need to sync my device with the computer clock so that the shutter responds at the correct time.

    I was told to run the code in Processing first in order to sync the clock with the time on the computer. There are also additional .pde files like TimeSerial and SyncArduinoClock that I have tried to run. Each time I run any of the codes (.pde files) in Processing I get the following error:

    unexpected char: 'i'


    I am not sure what this means because I have gone line by line in several of the files and either "i" is properly declared (to the best of my knowledge) or there is no "i" variable at all.

    I have attached a photo of the occurrence. If anyone could give me any insight on this subject matter I would greatly appreciate it. As silly as it may sound, I've been searching for solutions to this error for weeks and cannot seem to find much helpful information. I will post more info/entire code if it is needed/requested or helpful. I just have a feeling that this could be something really simple?

    I also tried this in an earlier version of Processing (1.5.1/Processing 2, I believe) and I got the same error message. I tried this because I know sometimes things change from version to version in programs like Arduino.

    Thank you all. shuttercodeerrorhelpplease

  • Magician-X of Dobot : a desktop robot arm of high precision, multi-controlled, and open-source ment

    Magician-X of Dobot is a desktop robot arm of high precision, multi-controlled, and open-source mental version. He is a desktop magician, made by cutting and CNC finished aluminum metal frame 6061. His brain is ARDUINO panel, the heart is a stepper motor, and have functions of eyes and ears. It can be placed on the desktop to interact with you and you can control it with gesture.

    It can do more things than you can imagine when connect with the other thing. Taking video by connecting with the PTZ camera. Connecting with 3D printing with its high precision.

    Does Dobot can do more things? Maybe, what it can do depend on what you can imaginede.Design by the Dobot team, if you are interested in it, come here to get more details:http://www.dobot.cc/home.html

  • positioning String

    hi everyone, I do not know how to change the position of the variable " val " to be in the position I want, this is my code..

     import controlP5.*;
     import processing.serial.*;
     
     
     ControlP5 cP5a;
     ControlP5 cP5b;
     ControlP5 cP5c;
     ControlP5 cP5d;
     ControlP5 cP5e;
     ControlP5 cP5f;
     ControlP5 cP5g;
     ControlP5 cP5h;
     
     Serial arduino;
     String val= "0";
     
     void setup() 
     {
       size(785, 520);
       println(Serial.list());
       String portName = Serial.list()[0];
       arduino = new Serial(this, portName, 9600);
     
     
       cP5a = new ControlP5(this);
       cP5a.addSlider("ATUR_KECEPATAN_MOTOR_DC", 0, 255, 0, 30, 155, 350, 50);
       cP5b = new ControlP5(this);
       cP5b.addButton("FORWARD",1,30,220,100,40);
       cP5c = new ControlP5(this);
       cP5c.addButton("REVERSE",0,280,220,100,40);
       cP5d = new ControlP5(this);
       cP5d.addButton("BUKA_GERBANG",1,30,300,100,40);
       cP5e = new ControlP5(this);
       cP5e.addButton("TUTUP_GERBANG",1,30,355,100,40);
       cP5f = new ControlP5(this);
       cP5f.addSlider("SUDUT_SERVO", 0, 180, 0, 30, 435, 350, 50);
       cP5g = new ControlP5(this);
       cP5g.addButton("MASTER_ON",1,30,80,100,35);
       cP5h = new ControlP5(this);
       cP5h.addButton("MASTER_OFF",0,160,80,100,35);
     }
     
     void draw() 
     {
       background(#614DED);
       textSize(20);
       fill(#F5ED00);
       text("PENGENDALI MOTOR DC MOTOR STEPPER DAN MOTOR SERVO", 100, 30);
       textSize(18);
       text("KECEPATAN MOTOR DC :", 500, 140);
       textSize(18);
       text("FIANSYAH AFANDI RAKHMAN, TEKNIK ELEKTRO, UNIVERSITAS SILIWANGI TASIKMALAYA", 10,60);
       textSize(15);
       text("A. MOTOR DC", 15,140);
       textSize(15);
       text("B. MOTOR STEPPER", 15,285);
       textSize(15);
       text("C. MOTOR SERVO", 15,420);
       textSize(13);
       fill(#020108);
       text("created by: Fiansyah Afandi Rakhman", 545, 500);
       text("107002025/elektro2010", 617, 515);
     
       if (arduino.available() >0){
         delay(100);
       val=arduino.readString();}  
       println(val);
     
     text(val, width/2, height/2);
     }
     void controlEvent(ControlEvent theEvent) {
       if(theEvent.isController()) {
     
       print("control event from : "+theEvent.controller().name());
       println(", value : "+theEvent.controller().value());
     
      if(theEvent.controller().name()=="ATUR_KECEPATAN_MOTOR_DC") {
        int val1 = int(theEvent.getController().getValue());
        arduino.write("a" + val1);
      }
      if(theEvent.controller().name()=="FORWARD") {
        int val2 = int(theEvent.getController().getValue());
       arduino.write("b" + val2 );
      }
      if(theEvent.controller().name()=="REVERSE") {
        int val3 = int(theEvent.getController().getValue());
        arduino.write("c" + val3);
         }
      if(theEvent.controller().name()=="BUKA_GERBANG") { 
         int val4 = int(theEvent.getController().getValue());
        arduino.write("d" + val4 );
      }
      if(theEvent.controller().name()=="TUTUP_GERBANG") { 
         int val5 = int(theEvent.getController().getValue());
       arduino.write("e" + val5 );
      }
      if(theEvent.controller().name()=="SUDUT_SERVO") {
        int val6 = int(theEvent.getController().getValue());
       arduino.write("f" + val6);  
      }
      if(theEvent.controller().name()=="MASTER_ON") {
        int val7 = int(theEvent.getController().getValue());
       arduino.write("g" + val7);
      }
      if(theEvent.controller().name()=="MASTER_OFF") {
        int val8 = int(theEvent.getController().getValue());
      arduino.write("h" + val8);
        }
       }
     }
    

    I want to ask is how to adjust the position of " val " to be positioned in the position I wanted.

     if (arduino.available() >0){
         delay(100);
         val=arduino.readString();
     }  
     println(val);
     
     text(val, width/2, height/2);
    
  • displaying string from Arduino

    Chrisir thank you , I really appreciate your help , and I am very happy . My problem is solved , but new problems arise , I do not know how to change the position of the variable " val " to be in the position I want, this is my code

       ` import controlP5.*;
        import processing.serial.*;
    
    
        ControlP5 cP5a;
        ControlP5 cP5b;
        ControlP5 cP5c;
        ControlP5 cP5d;
        ControlP5 cP5e;
        ControlP5 cP5f;
        ControlP5 cP5g;
        ControlP5 cP5h;
    
        Serial arduino;
        String val= "0";
    
        void setup() 
        {
          size(785, 520);
          println(Serial.list());
          String portName = Serial.list()[0];
          arduino = new Serial(this, portName, 9600);
    
    
          cP5a = new ControlP5(this);
          cP5a.addSlider("ATUR_KECEPATAN_MOTOR_DC", 0, 255, 0, 30, 155, 350, 50);
          cP5b = new ControlP5(this);
          cP5b.addButton("FORWARD",1,30,220,100,40);
          cP5c = new ControlP5(this);
          cP5c.addButton("REVERSE",0,280,220,100,40);
          cP5d = new ControlP5(this);
          cP5d.addButton("BUKA_GERBANG",1,30,300,100,40);
          cP5e = new ControlP5(this);
          cP5e.addButton("TUTUP_GERBANG",1,30,355,100,40);
          cP5f = new ControlP5(this);
          cP5f.addSlider("SUDUT_SERVO", 0, 180, 0, 30, 435, 350, 50);
          cP5g = new ControlP5(this);
          cP5g.addButton("MASTER_ON",1,30,80,100,35);
          cP5h = new ControlP5(this);
          cP5h.addButton("MASTER_OFF",0,160,80,100,35);
        }
    
        void draw() 
        {
          background(#614DED);
          textSize(20);
          fill(#F5ED00);
          text("PENGENDALI MOTOR DC MOTOR STEPPER DAN MOTOR SERVO", 100, 30);
          textSize(18);
          text("KECEPATAN MOTOR DC :", 500, 140);
          textSize(18);
          text("FIANSYAH AFANDI RAKHMAN, TEKNIK ELEKTRO, UNIVERSITAS SILIWANGI TASIKMALAYA", 10,60);
          textSize(15);
          text("A. MOTOR DC", 15,140);
          textSize(15);
          text("B. MOTOR STEPPER", 15,285);
          textSize(15);
          text("C. MOTOR SERVO", 15,420);
          textSize(13);
          fill(#020108);
          text("created by: Fiansyah Afandi Rakhman", 545, 500);
          text("107002025/elektro2010", 617, 515);
    
          if (arduino.available() >0){
            delay(100);
          val=arduino.readString();}  
          println(val);
    
        text(val, width/2, height/2);
        }
        void controlEvent(ControlEvent theEvent) {
          if(theEvent.isController()) {
    
          print("control event from : "+theEvent.controller().name());
          println(", value : "+theEvent.controller().value());
    
         if(theEvent.controller().name()=="ATUR_KECEPATAN_MOTOR_DC") {
           int val1 = int(theEvent.getController().getValue());
           arduino.write("a" + val1);
         }
         if(theEvent.controller().name()=="FORWARD") {
           int val2 = int(theEvent.getController().getValue());
          arduino.write("b" + val2 );
         }
         if(theEvent.controller().name()=="REVERSE") {
           int val3 = int(theEvent.getController().getValue());
           arduino.write("c" + val3);
            }
         if(theEvent.controller().name()=="BUKA_GERBANG") { 
            int val4 = int(theEvent.getController().getValue());
           arduino.write("d" + val4 );
         }
         if(theEvent.controller().name()=="TUTUP_GERBANG") { 
            int val5 = int(theEvent.getController().getValue());
          arduino.write("e" + val5 );
         }
         if(theEvent.controller().name()=="SUDUT_SERVO") {
           int val6 = int(theEvent.getController().getValue());
          arduino.write("f" + val6);  
         }
         if(theEvent.controller().name()=="MASTER_ON") {
           int val7 = int(theEvent.getController().getValue());
          arduino.write("g" + val7);
         }
         if(theEvent.controller().name()=="MASTER_OFF") {
           int val8 = int(theEvent.getController().getValue());
         arduino.write("h" + val8);
           }
          }
        }`
    

    I want to ask is how to adjust the position of " val " to be positioned in the position I wanted.

    text(val, width/2, height/2);

    thankyou...

  • displaying string from Arduino

    I control manages speed dc motor , I want to show the speed that is read by arduino , but the speed sent by arduino can only appear on the monitor serial processing , all I want is a display in the window " run" . this is processing code :

              `import controlP5.*;
                import processing.serial.*;
                ControlP5 cP5a;
                ControlP5 cP5b;
                ControlP5 cP5c;
                ControlP5 cP5d;
                ControlP5 cP5e;
                ControlP5 cP5f;
                ControlP5 cP5g;
                ControlP5 cP5h;
    
                Serial arduino;
                String val;
    
                void setup() 
                {
                  size(785, 520);
                  println(Serial.list());
                  arduino = new Serial(this, Serial.list()[0], 9600);
    
                  cP5a = new ControlP5(this);
                  cP5a.addSlider("ATUR_KECEPATAN_MOTOR_DC", 0, 255, 0, 30, 155, 350, 50);
                  cP5b = new ControlP5(this);
                  cP5b.addButton("FORWARD",1,30,220,100,40);
                  cP5c = new ControlP5(this);
                  cP5c.addButton("REVERSE",0,280,220,100,40);
                  cP5d = new ControlP5(this);
                  cP5d.addButton("BUKA_GERBANG",1,30,300,100,40);
                  cP5e = new ControlP5(this);
                  cP5e.addButton("TUTUP_GERBANG",1,30,355,100,40);
                  cP5f = new ControlP5(this);
                  cP5f.addSlider("SUDUT_SERVO", 0, 180, 0, 30, 435, 350, 50);
                  cP5g = new ControlP5(this);
                  cP5g.addButton("MASTER_ON",1,30,80,100,35);
                  cP5h = new ControlP5(this);
                  cP5h.addButton("MASTER_OFF",0,160,80,100,35);
                }
    
                void draw() 
                {
                  background(#614DED);
                  textSize(20);
                  fill(#F5ED00);
                  text("PENGENDALI MOTOR DC MOTOR STEPPER DAN MOTOR SERVO", 100, 30);
                  textSize(18);
                  text("KECEPATAN MOTOR DC :", 500, 140);
                  textSize(18);
                  text("FIANSYAH AFANDI RAKHMAN, TEKNIK ELEKTRO, UNIVERSITAS SILIWANGI TASIKMALAYA", 10,60);
                  textSize(15);
                  text("A. MOTOR DC", 15,140);
                  textSize(15);
                  text("B. MOTOR STEPPER", 15,285);
                  textSize(15);
                  text("C. MOTOR SERVO", 15,420);
                  textSize(13);
                  fill(#020108);
                  text("created by: Fiansyah Afandi Rakhman", 545, 500);
                  text("107002025/elektro2010", 617, 515);
    
                  if (arduino.available() >0){
                  val=arduino.readStringUntil('\n');}
    
                  println(val);
    
                }
    
                void controlEvent(ControlEvent theEvent) {
                  if(theEvent.isController()) {
    
                  print("control event from : "+theEvent.controller().name());
                  println(", value : "+theEvent.controller().value());
    
                 if(theEvent.controller().name()=="ATUR_KECEPATAN_MOTOR_DC") {
                   int val1 = int(theEvent.getController().getValue());
                   arduino.write("a" + val1);
                 }
                 if(theEvent.controller().name()=="FORWARD") {
                   int val2 = int(theEvent.getController().getValue());
                  arduino.write("b" + val2 );
                 }
                 if(theEvent.controller().name()=="REVERSE") {
                   int val3 = int(theEvent.getController().getValue());
                   arduino.write("c" + val3);
                    }
                 if(theEvent.controller().name()=="BUKA_GERBANG") { 
                    int val4 = int(theEvent.getController().getValue());
                   arduino.write("d" + val4 );
                 }
                 if(theEvent.controller().name()=="TUTUP_GERBANG") { 
                    int val5 = int(theEvent.getController().getValue());
                  arduino.write("e" + val5 );
                 }
                 if(theEvent.controller().name()=="SUDUT_SERVO") {
                   int val6 = int(theEvent.getController().getValue());
                  arduino.write("f" + val6);  
                 }
                 if(theEvent.controller().name()=="MASTER_ON") {
                   int val7 = int(theEvent.getController().getValue());
                  arduino.write("g" + val7);
                 }
                 if(theEvent.controller().name()=="MASTER_OFF") {
                   int val8 = int(theEvent.getController().getValue());
                 arduino.write("h" + val8);
                   }
                  }
                }`
    

    in this section :

        if (arduino.available() >0){
        val=arduino.readStringUntil('\n');}
        println(val);
    

    when i added into :

            if (arduino.available() >0){
                                      val=arduino.readStringUntil('\n');}
    
                                      println(val);
                                    textSize(18);
                                    text(val, 500, 180);
    

    there is an error, and there is written "could'nt run the sketch" and the problem is this section :

                text(val, 500, 180)
    

    help me to solve this problem , how to correct sketch writing if you want to display a string on the run window . Thank you , any help would be greatly appreciated

  • split int produces null yet split float produces numbers.
    the first code I posted was my retype accounting for the errors
    

    the following is pasted.... I have yet to figure out how to get the line numbers as from above.... regardless,

    this code works fine when split string feeds a floats array however when you comment out the float declarations, and use the int declarations, s0 and s1 print '0'

    the Arduino is driving 2 steppers off an Adafruit stepper shield and sends feed back when either stepper 'steps to end' changes value

    the expected (an actual) feedback stream is a two value countdown from 128 at two different rates. this gets printed out and verified by the println(inString);

            <pre>      
            /*
            "feedback from arduino steppers stripped"....
            working against 
            "I 2 steppers driven by processing"
            returns feedback
            05 16 2015
            */
            int CarrageReturn = 13;
            //int [] stepFeedBack = new int[1];              //Array to hold the stepper feed back
            float [] stepFeedBack = new float[1];              //Array to hold the stepper feed back
            int MaxSpeed1 = 100, AccelRate1 = 200, TotalSteps1 = 128;  
            int MaxSpeed2 = 10, AccelRate2 = 200, TotalSteps2 = 128;
            int motorDataIsNext = 0;
            //int s1 = 0, s0 = 0;
            float s1 = 0, s0 = 0;
            String inString;  
            int firstPass = 0;              //limits the initial draw to one  pass
              import processing.serial.*; //import the Serial library
              Serial myPort;              //the Serial port object
            void setup() {  
                  size(200, 200);                              
                  myPort = new Serial(this, "COM3", 4800);      //  initialize serial port and set baud rate  
            } // .................................. End of Set Up ....
            void draw() {
              //incoming text at start up is ignored
              //first usable serial string is the flag for "Contact made" (0.01)
              //motorData is set to 1 with the mouseclick
              //the next set of strings are steps remaining (#0, #1)
              // 2 numbers separated by a ","
              // end of motor run is indicated by '0.90' string
                  if (firstPass == 0){ // .... this is the first pass after setup 
                       firstPass = 1;  
                    }              
                     else if (myPort.available () > 0){
                            inString = myPort.readStringUntil(CarrageReturn);               //put the incoming data into a String - 
             //               println(inString);  //THIS LINE PRINTS EVERYTHING COMING IN ON THE SERIAL PORT.... SAVE FOR TESTING......
                          if (inString != null) {                             //if inString IS NOT empty
             //               println(inString);  //THIS LINE PRINTS EVERYTHING COMING IN ON THE SERIAL PORT.... SAVE FOR TESTING...... 
                           if (float(inString) == 0.90){                //this tests for Motor Number flag (0.9 is the end of steps)
                              println("End of Motor Run");      //This steppers are done
                              motorDataIsNext = 0;        //set flag NOT to expect motor feedback in the next string
                              myPort.clear();
                           }               
                            else if (motorDataIsNext == 1){                  //incoming motor data
                               println(inString);            //THIS LINE PRINTS EVERYTHING COMING IN ON THE SERIAL PORT.... SAVE FOR TESTING......
            //                  int [] stepFeedBack = int(split(inString, ','));
                              float [] stepFeedBack = float(split(inString, ','));
    
                               //println(inString);  //THIS LINE PRINTS EVERYTHING COMING IN ON THE SERIAL PORT.... SAVE FOR TESTING......
                                s0 = (stepFeedBack[0]);
                                s1 = (stepFeedBack[1]);
                                println (s0);
                                println (s1);
                              }
                            else if (float(inString) == 0.01){                          // this is the flag for "Contact made" sent by Arduino
                               println("Contact");
                             }
                          } 
                     }
            } // .................................. End of Draw ....
            void mouseClicked(){
               String cos = "";
               cos = (str(MaxSpeed1) + "," + str(AccelRate1) + "," + str(TotalSteps1)+ "," + str(MaxSpeed2) + "," + str(AccelRate2) + "," + str(TotalSteps2));
               println (cos);
               myPort.write(cos);      //send a string to run two steppers at max speed, accel and steps
               motorDataIsNext = 1;
            }//........................................ end void mouseclicked ........................
            </pre>      
    

    I feel a little silly chasing a problem when the code works with float declarations. But, I would like to know why it doesn't work with int declarations.

  • Serial Port Problem "Error opening serial port COM1: Port not found"

    Hello guys, I am a student who is working on my bachelor thesis.

    I am dealing with stepper motors and the controller using Arduino, and I am creating a GUI for my stepper motor to control it. I try Processing, and it seems simple and powerful enough.

    However, I encountered a problem when I am running Processing program. "Error opening serial port COM1: Port not found"

    I use Ubuntu OS 14.04, Processing 2.2.1, and Arduino IDE 1.0.5.

    This problem appeared as soon as I run my processing code, right after I uploaded my Arduino code.

    Anybody can help to fix this issue?

    Thanks very much! :)

  • Send Value from ControlP5 to arduino serial communication

    I have 3 motors , DC motor , servo motor and stepper motor, for this project. Everything would I run with the processing and arduino . But I really feel stuck . The main problem is I can not send data from the toggle , slider and textfield of ControlP5 to be sent to the arduino, please help me make a sketch for how to send each value of the slider toggle and the other to be accepted by the arduino . thank you your help would be greatly appreciated.

    this is processing code :

        import controlP5.*;
        import processing.serial.*;
    
        ControlP5 cP5a;
        ControlP5 cP5b;
        ControlP5 cP5c;
        ControlP5 cP5d;
        ControlP5 cP5e;
    
        Serial arduino;
    
        int MOTOR_DC_SPEED_CONTROL = 0;
        boolean CHANGE_DIRECTION = false;
        String STEPPER_STEP = "";
        String STEPPER_SPEED_CONTROL = "";
        int SERVO_ANGLE = 0;
    
    
        void setup() 
        {
          size(600, 450);
          String portName = Serial.list()[0];
          arduino = new Serial(this, portName, 9600);
    
          cP5a = new ControlP5(this);
          cP5a.addSlider("MOTOR_DC_SPEED_CONTROL", 0, 255, 0, 30, 95, 255, 35);
          cP5b = new ControlP5(this);
          cP5b.addToggle("CHANGE_DIRECTION", false, 30, 145, 35, 35);
          cP5c = new ControlP5(this);
          cP5c.addTextfield("STEPPER_STEP")
             .setPosition(30,235)
             .setSize(128,35)
             .setAutoClear(false);
          cP5c.addBang("clear")
             .setPosition(168,235)
             .setSize(80,35)
             .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER);
          cP5d = new ControlP5(this);
          cP5d.addTextfield("STEPPER_SPEED_CONTROL")
             .setPosition(30,295)
             .setSize(128,35)
             .setAutoClear(false);
          cP5d.addBang("clear")
             .setPosition(168,295)
             .setSize(80,35)
             .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER);
          cP5e = new ControlP5(this);   
          cP5e.addSlider("SERVO_ANGLE", 0, 180, 0, 30, 380, 255, 35);   
        }
    
        void draw() 
        {
          background(128);
          fill(0, 0, 153);
          text("DC MOTOR STEPPER MOTOR  & SERVO MOTOR CONTROLLER", 115, 20);
          text("FIANSYAH AFANDI RAKHMAN, ELECTRICAL ENGINEERING, SILIWANGI UNIVERSITY, INDONESIA", 45,43);
          text("A. DC MOTOR", 15,75);
          text("B. STEPPER MOTOR", 15,215);
          text("C. SERVO MOTOR", 15,365);
          text("created by: Fiansyah Afandi Rakhman", 375, 442);
    
        }
            void controlEvent(ControlEvent theEvent) {
            //if(theEvent.isAssignableFrom(Textfield.class)) 
            if(theEvent.isController()) {  
    
            print("control event from : "+theEvent.controller().name());
            println(", value : "+theEvent.controller().value());
            println("controlEvent: accessing a string from controller '"
                    +theEvent.getName()+"': "
                    +theEvent.getStringValue());
    
    
    
    
    
            if(theEvent.controller().name()=="MOTOR_DC_SPEED_CONTROL") {
    
            }
            if(theEvent.controller().name()=="CHANGE_DIRECTION") {
    
            }
            if(theEvent.controller().name()=="STEPPER_STEP") {
    
            }
            if(theEvent.controller().name()=="STEPPER_SPEED_CONTROL") {
    
            }
            if(theEvent.controller().name()=="SERVO_ANGLE") {
    
                } 
              }
            }
           public void clear() {
            cP5c.get(Textfield.class,"STEPPER_STEP").clear();
            cP5d.get(Textfield.class,"STEPPER_SPEED_CONTROL").clear();
        }
    

    I am confused in this section :

                    if(theEvent.controller().name()=="MOTOR_DC_SPEED_CONTROL") {
    
                    }
                    if(theEvent.controller().name()=="CHANGE_DIRECTION") {
    
                    }
                    if(theEvent.controller().name()=="STEPPER_STEP") {
    
                    }
                    if(theEvent.controller().name()=="STEPPER_SPEED_CONTROL") {
    
                    }
                    if(theEvent.controller().name()=="SERVO_ANGLE") {
    
                        } 
    

    how to continue sending signals generated by each of the objects , and how to differentiate between each other in order to command the right target .

    and this is the arduino code to receive a signal :

            #include <Servo.h>
            #include <Stepper.h>
    
            Servo myservo;
    
            int in1Pin = 5;   // for stepper
            int in2Pin = 6;   // for stepper
            int relayPin = 8;  // for dcmotor change direction
            int in1dcPin = 10;  // for dcmotor
            int in2dcPin = 9;   // for dcmotor
            int enablePin = 11;   // for dcmotor
            int switchPin = 7;   // for dcmotor change direction
    
            char val;           // for relay as changer direction
            int valServo;   // for servo angle
    
            Stepper motor(48, in1Pin, in2Pin);
    
            void setup(){
              pinMode(in1Pin, OUTPUT);
              pinMode(in2Pin, OUTPUT);
              pinMode(in1dcPin, OUTPUT);
              pinMode(in2dcPin, OUTPUT);
              pinMode(enablePin, OUTPUT);
              pinMode(switchPin, INPUT_PULLUP);
              pinMode(relayPin, OUTPUT);
              myservo.attach(9);
              while (!Serial);
              Serial.begin(9600);
    
              motor.setSpeed('myspeed');
            }
    
            void loop(){
                boolean reverse = digitalRead(switchPin);
                 if (Serial.available()) {
                {
                  int incomeByte = Serial.parseInt(); // read from motordcspeedcontrol's 1st slider
                  setMotor(incomeByte, reverse);
                  analogWrite(enablePin, incomeByte);    }  //
    
                {
                  val = Serial.read(); // read from changedirection's togggle
                  if (val == '1')
                  { digitalWrite(relayPin, HIGH);}
                  else
                  {digitalWrite(relayPin, LOW);}
                  delay(10);                             } // for relay changer of motor direction
    
                {
                  int steps = Serial.parseInt(); // read from stepperstep's 2nd slider
                  motor.step(steps);                     } // for step of steppermotor
    
                {
                  int myspeed = Serial.parseInt(); // read from stepperspeedcontrol's 3rd slider
                  motor.setSpeed(myspeed);               } // for speed of steppermotor
                  static int v = 0;
                {
                  valServo = Serial.read(); 
                  valServo = map(val, 0, 1024, 0, 180);
                  myservo.write(valServo);   
                  delay(15);                             }
              }
            }
    
              void setMotor(int speed, boolean reverse)
                {
    
                digitalWrite(in1dcPin, ! reverse);
                digitalWrite(in2dcPin, reverse);
                }