Pwm dimmer led android

Hi Noel
yes in fact, I rotate the motor then the encoder on the same axis and consequently the needle of the circle must move on android,
on java; yes it does and transmits via serial (maybe I will not have posted the part of the serial)
however I want to clarify that everything works with dc motor and not step by step
so the code you posted above i believe it is not for my engine but for step by step
let me know thanks

OK. So if you post the serial code that you use to send data to the pc processing sketch, I can write the Android receiver code. I need to know how you are sending your data.

import processing.serial.*;
Serial myPort; 
String myString = null;
int incoming_position = 0;
float position_in_degree = 0;
PFont font18,font63;

void setup(){
  size(800, 600);
  font18 = loadFont("Tahoma-18.vlw");
  font63 = loadFont("Tahoma-63.vlw");
  
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
}

void draw(){
  background(100);
  textFont(font63, 36);
  text("RAW Position:", 30, 510);
  text(incoming_position, 270, 510);
  text("Position in Degree:", 30, 550);
  text(position_in_degree, 330, 550);
  draw_angle(400,250,200,position_in_degree); // draw circle and encoder position
  
  // Reading Serial Port when buffer not zero
while (myPort.available() > 0) {
    myString = myPort.readStringUntil(10); // Read Data from Serial until line feed (10)
    if (myString != null) {
      myString = trim(myString); // Remove Line Feed
      incoming_position = int(myString); // String to int
      position_in_degree = map(incoming_position,0, 1023, 0,359.999); // translate raw position in to 360 degree position format
      println(position_in_degree);
    }
  }
  
}

void draw_angle(int x, int y,int size, float angle_dec){
  noFill();
  stroke(255,255,255,255);
  // X,Y plane Translation
  float end_x,end_y;
  float angle_rad = radians(angle_dec);
  end_x = x + cos(angle_rad)*size; 
  end_y = y + sin(angle_rad)*size;
  // mark angle guage in circle
  line(x,y,end_x,end_y);
  
  int space = 20;
  int space2 = size - space;
  ellipse(x, y, size*2+space, size*2+space);
  
  // mark small tick on cicle every 15 degree
  for(int i = 0; i < 360; i = i +15){ 
    float rad1 = radians(i);
    // mark large scale on 0 90 180 270 degree
    if( i == 0 || i == 90 || i == 180 || i == 270){ 
      line(x + cos(rad1)*space2,y + sin(rad1)*space2,x + cos(rad1)*(size+space),y + sin(rad1)*(size+space));
    }else{
      line(x + cos(rad1)*space2,y + sin(rad1)*space2,x + cos(rad1)*size,y + sin(rad1)*size);
    }
  }
  
}

. . . . .I mean the Arduino serial code that you use to send data to the pc processing sketch

Edit. Looking at this code in this line:

position_in_degree = map(incoming_position,0, 1023, 0,359.999);

Your Arduino code is sending strings from number 0 to 1023 (to give the angle), so that’s enough as well. Tonight I will post the code.

the data from 0 to 1023 are sent by the encoder through the sketch I posted to you some post above

I understood this already, therefore I edited my post soon after posting.I have it already working nicely. After lunch ( and a nap :wink: ), I will post it.

226 / 5000

Risultati della traduzione

noel I would need to be able to set the position of the motor example say go to position example 300 (then the program reads the encoder steps and the mortor moves to position 300 Could you give me info?

The Ketai lib can’t handle fast incoming data, so I wrote a Bluetooth code that does.
I posted that code here and added also the code you requested as an example for others as well.
I kept your design, because I think it’s nice, but re-wrote the code as a class to easily construct multiple knobs if needed. Don’t forget to give the needed permissions.

But that was my first understanding of your request because it seemed more obvious to me that you want to control your motor, and not only visualize the axis position. That is where the Arduino code I wrote above is for (stepper) Of course you can do this as well with the dc motor since you have an encoder coupled to the axis. The picture shows me that you have a slider, I assume it’s for the speed control, but without seeing the whole Arduino code I can’t say much. It also depends on what the motor is connected to, because you are using a more potent motor, and together with the load they can generate high kinetic energy so that you need to decrease the velocity before the actual stopping.

void moveMotorRight() {
if ((position2reach - actualPos) < 10) { // reduce the speed if there is 1000 point to the targer position
motorSpeed = 200;
} else {
motorSpeed = 50;
}

Did you have this already in your code?

no, I have a good code but it is for python and runs under windows with arduino and honestly I don’t like this os so much but how it works is good and malleable in everything only that should be modified for android

[image]

Noel where you ?
i need help

I will not answer any questions anymore because I’m leaving this forum unless my request being accepted. My ego just can’t accept an unjustifiable accusation. You were pinged at did not react. I am very disappointed.

(You received a ping and did not react. I am very disappointed.) what does it mean

But what do you say I don’t know what a ping is
also I always have to use google to translate so everything is new to me
so explain to me what happened as I no longer receive posts regarding my requests

Anyway I wanted to tell you that I tried your code for the circle and it works great with my 200 step encoder for rotation

@noel

Please don’t take things that happen here too seriously. Life is short. Personally, I think you do a great job and are the main reason I hang around over here.

With regard to the initial reason for this thread (which was a flicker of the encoder gauge) I believe the problem was on the Android end when the serial bluetooth data was reconstructed. The data was not being perfectly parsed and sometimes gave spurious results, which gave the flicker when plotted. The demo that you posted (using Android bluetooth code) appears to have solved the problem. It needs further testing but it appears to work as far as stopping the flicker (due to better parsing code). Thanks for the post.

Hello Svan
?
I don’t understand what I have done something wrong or did something wrong? let me know … then the ping issue that I don’t understand
Thanks

@r0x15

Sounds like a communication problem. I was not involved so can not respond.

ok
Thank you very much

you are one of the best stay many count-on you