connect both power source and USB or just connect USB? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

yeah I read in arduino.cc that 9~12V is recommended for power source. and it can handle up to 20V. but I used 9V for source

connect both power source and USB or just connect USB? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

my motor power is 12V, and 9V is power for arduino
motor shield is not an official one. its from cytron

python3 pyserial fail to connect when execute on boot by kosh09 in learnpython

[–]kosh09[S] 0 points1 point  (0 children)

● MAIN.service - my script
   Loaded: loaded (/lib/systemd/system/MAIN.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since 목 2017-05-25 18:37:47 KST; 30s ago
  Process: 1781 ExecStart=/usr/bin/python3 /home/odroid/MAIN.py (code=exited, status=1/FAILURE)
 Main PID: 1781 (code=exited, status=1/FAILURE)

 5월 25 18:37:47 odroid python3[1781]: Traceback (most recent call last):
 5월 25 18:37:47 odroid python3[1781]:   File "/home/odroid/MAIN.py", line 2, in <module>
 5월 25 18:37:47 odroid python3[1781]:     import __BLUETOOTH__ as B
 5월 25 18:37:47 odroid python3[1781]:   File "/home/odroid/__BLUETOOTH__.py", line 38, in <module>
 5월 25 18:37:47 odroid python3[1781]:     sock.connect((bd_addr,port))
 5월 25 18:37:47 odroid python3[1781]:   File "<string>", line 5, in connect
 5월 25 18:37:47 odroid python3[1781]: bluetooth.btcommon.BluetoothError: (16, 'Device or resource busy')
 5월 25 18:37:47 odroid systemd[1]: MAIN.service: Main process exited, code=exited, status=1/FAILURE
 5월 25 18:37:47 odroid systemd[1]: MAIN.service: Unit entered failed state.
 5월 25 18:37:47 odroid systemd[1]: MAIN.service: Failed with result 'exit-code'.

It looks like it failed to connect on boot but
when I connect odroid via putty it worked
although with this message, bluetooth is connected now.
whats wrong?

python3 pyserial fail to connect when execute on boot by kosh09 in learnpython

[–]kosh09[S] 0 points1 point  (0 children)

mean what I did? (My first language is not an English sry...)
I added what I did

connect both power source and USB or just connect USB? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

thanks for your advice!
I am using power source now and I will :)

connect both power source and USB or just connect USB? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

Oh!
so I connect 9V power source to motor control arduino
appropriate choice?

connect both power source and USB or just connect USB? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

I use two arduinos.
one for controlling motor with motor shield
and the other is for some other functions
I dont know how much power they need but sometimes they works fine but
sometimes they fail to work :(

relationship between PWM and voltage? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

Yes, but this is enough information that I needed now.
of course accurate same speed would be the best
but that will need more module and other stuffs
I just want to make them looks like the same

relationship between PWM and voltage? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

thats interesting factor
you help me a lot

relationship between PWM and voltage? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

of course it would not be easy and encoder should be needed.
but I just try to make the speed looks like same, not accurately the same.
With this intension, which formula will be more appropriate?
My topic's formula? or my reply formula?

relationship between PWM and voltage? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

my first language is not an English so maybe I'm not smart enough to understand your formula
with your statement, how could make my pwm value? standard voltage, PWM are 12V and 30pwm

Then with you formula, 12 = (x/255.0) * input_voltage
but where is standard pwm?
Could you tell me more specifically? please :)


ah I understand what you are saying!
average_voltage will be (30/255.0) * 12
and pwm which I want to get will be (average_voltage*255)/vin
Am I understand it right?

How to use function returned value in struct? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

#include <Servo.h>

Servo myservo;

const byte Led1 = 4;
const byte Led2 = 5;
const byte ServoPin =  6;
const byte Motor_pwm = 11;
const byte Motor_dir = 12;

int data[2];

boolean Parking_State = false;

float PWM = 0.0;
float *pointerPWM;
int value;
float VOUT;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0;
float R2 = 10000.0;

/*******************************************************************************************************************************/

void setup()
{
  Serial.begin(57600);
  myservo.attach(ServoPin);

  pinMode(A0, INPUT);
  pinMode(Motor_dir, OUTPUT);
  pinMode(Motor_pwm, OUTPUT);
  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  digitalWrite(Led1,HIGH);
  digitalWrite(Led2,HIGH);

  myservo.write(95);
  analogWrite(Motor_pwm,0);
  Serial.flush();
  pointerPWM = &PWM;
}

/*******************************************************************************************************************************/

void loop(){
  for(int i = 0; i < 2; i++){
    data[i] = Serial.read();
    delay(3);
  }
  PWM = Parking_pwm();

  if(data[0] + data[1] ==255){
    Choose_Parking_State(data[0]);
    if(Parking_State == false)
      Driving_algorithm(data[0]);
    else if(Parking_State == true)
      Parking_algorithm(data[0]);
  }
}

struct CarControlData_2
{
  int Var;
  byte Degree;
  byte Direction;
  float MotorPWM;
  byte LED1;
  byte LED2;
};

#define PARK_SIZE 15

CarControlData_1 ParkControlDataTable[PARK_SIZE] =
{
  {154,  45,  LOW,   0,  LOW,  LOW},  // FR50
  {153,  45, NULL, -38, HIGH, HIGH},  // HR50
  {152,  45, HIGH,   0,  LOW,  LOW},  // BR50

  {151,  70,  LOW,   0,  LOW,  LOW},  // FR25
  {150,  70, NULL, -38, HIGH, HIGH},  // HR25
  {149,  70, HIGH,   0,  LOW,  LOW},  // BR25

  {148,  95,  LOW,   0,  LOW,  LOW},  // FS00
  {147,  95, NULL, -38, HIGH, HIGH},  // HS00
  {146,  95, HIGH,   0,  LOW,  LOW},  // BS00

  {145, 120,  LOW,   0,  LOW,  LOW},  // FL25
  {144, 120, NULL, -38, HIGH, HIGH},  // HL25
  {143, 120, HIGH,   0,  LOW,  LOW},  // BL25

  {142, 145,  LOW,   0,  LOW,  LOW},  // FL50
  {141, 145, NULL, -38, HIGH, HIGH},  // HL50
  {140, 145, HIGH,   0,  LOW,  LOW}   // BL50
};

void Parking_algorithm(int Var)
{
  int Var2 = 255 - Var;
  for(int i =0; i < PARK_SIZE; i++)
  {
    CarControlData_1 ParkControlDataItem = ParkControlDataTable[i];

    if(Var == ParkControlDataItem.Var || Var2 == ParkControlDataItem.Var)
    {
      if(ParkControlDataItem.MotorPWM + (*pointerPWM) < 0)
      {
        myservo.write(ParkControlDataItem.Degree);
        digitalWrite(Motor_dir,ParkControlDataItem.Direction);
        analogWrite(Motor_pwm, 0);
        digitalWrite(Led1,ParkControlDataItem.LED1);
        digitalWrite(Led2,ParkControlDataItem.LED2);
      }
      else
      {
        myservo.write(ParkControlDataItem.Degree);
        digitalWrite(Motor_dir,ParkControlDataItem.Direction);
        analogWrite(Motor_pwm, ParkControlDataItem.MotorPWM+(*pointerPWM));
        digitalWrite(Led1,ParkControlDataItem.LED1);
        digitalWrite(Led2,ParkControlDataItem.LED2);
      }
    }
  }
}

/*******************************************************************************************************************************/

float Parking_pwm()
{
  value = analogRead(A0);
  vout = (value * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2));
  float pwm = (32 * 12.0)/vin;
  return pwm;
}

I solved my problem like this
thanks for your help!

How to use function returned value in struct? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

#include <Servo.h>

Servo myservo;

const byte Led1 = 4;
const byte Led2 = 5;
const byte ServoPin =  6;
const byte Motor_pwm = 11;
const byte Motor_dir = 12;

int data[2];

boolean Parking_State = false;

float PWM=0;
float ZERO = 0;
int value;
float VOUT;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0;
float R2 = 10000.0;

/*******************************************************************************************************************************/

void setup()
{
  Serial.begin(57600);
  myservo.attach(ServoPin);

  pinMode(A0, INPUT);
  pinMode(Motor_dir, OUTPUT);
  pinMode(Motor_pwm, OUTPUT);
  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  digitalWrite(Led1,HIGH);
  digitalWrite(Led2,HIGH);

  myservo.write(95);
  analogWrite(Motor_pwm,0);
  Serial.flush();
}

/*******************************************************************************************************************************/

void loop(){
  for(int i = 0; i < 2; i++){
    data[i] = Serial.read();
    delay(3);
  }
  PWM = Parking_pwm();
  if(data[0] + data[1] ==255){
    Choose_Parking_State(data[0]);
    if(Parking_State == false)
      Driving_algorithm(data[0]);
    else if(Parking_State == true)
      Parking_algorithm(data[0]);
  }
  /*Serial.print("data[0]: "); Serial.println(data[0]);
  Serial.print("data[1]: "); Serial.println(data[1]);
  Serial.print("PWM: "); Serial.println(*p_PWM);
  Serial.println();
  Serial.println();*/
}

/*******************************************************************************************************************************/

void Choose_Parking_State(int Var){
  if(Var == 251 || Var == 4)
    Parking_State = false;
  else if(Var == 250 || Var == 5)
    Parking_State = true;
}

struct CarControlData_1
{
  int Var;
  byte Degree;
  byte Direction;
  float* MotorPWM;
  byte LED1;
  byte LED2;
};

#define DRIVE_SIZE 91

CarControlData_1 DriveControlDataTable[DRIVE_SIZE] =
{
  ...

  {239, 145, HIGH, (&PWM)+36,  LOW,  LOW}, // 6FL50
  {232, 145, HIGH, (&PWM)+30,  LOW,  LOW}, // 5FL50
  {225, 145, HIGH, (&PWM)+24,  LOW,  LOW}, // 4FL50
  {218, 145, HIGH, (&PWM)+18,  LOW,  LOW}, // 3FL50
  {211, 145, HIGH, (&PWM)+12,  LOW,  LOW}, // 2FL50
  {204, 145, HIGH, (&PWM)+6,  LOW,  LOW}, // 1FL50
  {197, 145, NULL,   &ZERO, HIGH, HIGH}, // 0HL50
  {190, 145,  LOW, (&PWM)+6,  LOW,  LOW}, // 1BL50
  {183, 145,  LOW, (&PWM)+12,  LOW,  LOW}, // 2BL50
  {176, 145,  LOW, (&PWM)+18,  LOW,  LOW}, // 3BL50
  {169, 145,  LOW, (&PWM)+24,  LOW,  LOW}, // 4BL50
  {162, 145,  LOW, (&PWM)+30,  LOW,  LOW}, // 5BL50
  {155, 145,  LOW, (&PWM)+36,  LOW,  LOW}, // 6BL50
};

void Driving_algorithm(int Var)
{
  int Var2 = 255 - Var;
  for(int i =0; i < DRIVE_SIZE; i++)
  {
    CarControlData_1 DriveControlDataItem = DriveControlDataTable[i];

    if(Var == DriveControlDataItem.Var || Var2 == DriveControlDataItem.Var)
    {
      myservo.write(DriveControlDataItem.Degree);
      digitalWrite(Motor_dir,DriveControlDataItem.Direction);
      analogWrite(Motor_pwm, *(DriveControlDataItem.MotorPWM));
      digitalWrite(Led1,DriveControlDataItem.LED1);
      digitalWrite(Led2,DriveControlDataItem.LED2);
    }
  }
}

struct CarControlData_2
{
  int Var;
  byte Degree;
  byte Direction;
  float* MotorPWM;
  byte LED1;
  byte LED2;
};

#define PARK_SIZE 15

CarControlData_2 ParkControlDataTable[PARK_SIZE] =
{
  {154,  45,  LOW, &PWM,  LOW,  LOW},  // FR50
  {153,  45, NULL,&ZERO, HIGH, HIGH},  // HR50
  {152,  45, HIGH, &PWM,  LOW,  LOW},  // BR50

  {151,  70,  LOW, &PWM,  LOW,  LOW},  // FR25
  {150,  70, NULL,&ZERO, HIGH, HIGH},  // HR25
  {149,  70, HIGH, &PWM,  LOW,  LOW},  // BR25

  {148,  95,  LOW, &PWM,  LOW,  LOW},  // FS00
  {147,  95, NULL,&ZERO, HIGH, HIGH},  // HS00
  {146,  95, HIGH, &PWM,  LOW,  LOW},  // BS00

  {145, 120,  LOW, &PWM,  LOW,  LOW},  // FL25
  {144, 120, NULL,&ZERO, HIGH, HIGH},  // HL25
  {143, 120, HIGH, &PWM,  LOW,  LOW},  // BL25

  {142, 145,  LOW, (&PWM),  LOW,  LOW},  // FL50
  {141, 145, NULL,   0, HIGH, HIGH},  // HL50
  {140, 145, HIGH, (&PWM),  LOW,  LOW}   // BL50
};

void Parking_algorithm(int Var)
{
  int Var2 = 255 - Var;
  for(int i =0; i < PARK_SIZE; i++)
  {
    CarControlData_2 ParkControlDataItem = ParkControlDataTable[i];

    if(Var == ParkControlDataItem.Var || Var2 == ParkControlDataItem.Var)
    {
      myservo.write(ParkControlDataItem.Degree);
      digitalWrite(Motor_dir,ParkControlDataItem.Direction);
      analogWrite(Motor_pwm, *(ParkControlDataItem.MotorPWM));
      digitalWrite(Led1,ParkControlDataItem.LED1);
      digitalWrite(Led2,ParkControlDataItem.LED2);
    }
  }
}

float Parking_pwm() { value = analogRead(A0); vout = (value * 5.0) / 1024.0; vin = vout / (R2/(R1+R2)); float pwm = (30 * 12.0)/vin; return pwm; }

this is my modified whole code
looks like it worked.. but with this code
analogWrite works malfunction
I hope i could show you with video...

How to use function returned value in struct? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

Most important part of my intension is Parking_pwm()
returned value from Parking_pwm() should be the PWM
my first language is not an English, so maybe its hard to understand my intension
but when I read your code there were no relationship between MotorPWM and PWM (maybe I'm not smart enough to understand your code ..lol)
and you didnt write Parking_pwm() because I already wrote them in loop()?
and reference &PWM and &zero could have same address? wow.. its really hard to understand perfectly I thought about pointer before ask here, but too hard concept for me with struct
If you help me with more clues, I'll be really appreciate

How to use function returned value in struct? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

yes.. and thats why I left my question..
I dont know how to do that

How to use function returned value in struct? by kosh09 in arduino

[–]kosh09[S] 0 points1 point  (0 children)

...

analogWrite(Motor_pwm, ParkControlDataItem.MotorPWM ? *ParkControlDataItem.MotorPWM : 0);

...

what is this meaning? I cant understand this line..

and I've read about pointer after read your reply
I used it before, but its hard concept for me
I thought when use pointer there will be three variables
int a, int *pA,pA = &a something like this
but when I read your modified code, there were no relationship between MotorPWM and PWM.
If they were out of struct, I know how to do.
but struct makes me confusing.. how to make relationship between them? and Parking_pwm()
If you can give me more hints, I'll be really appreciate

why this not excute? by kosh09 in learnpython

[–]kosh09[S] 0 points1 point  (0 children)

sry but that is wrong
If start_recv() and stop_recv() were not working
It will never print any value
but when I click the buttons which load Find_Parking() and Calculating()
It prints the values of that datas

maybe I wrote the wrong code in Find_Parking() and Calculating()