Here is the updated code that will process the serial data coming from the Arduino. The problem is that the values from the Arduino are not scaled.
0 = 0/255 = 0%
100 = 100/255 = 39%
150 = 150/255 = 59%
200 = 200/255 = 78%
250 = 250/255 = 98%
On the Propeller these translate to
0 = 0/600 = 0%
100 = 100/600 = 17%
150 = 150/600 = 25%
200 = 200/600 = 33%
250 = 250/600 = 42%
/*
Blank Simple Project.c
http://learn.parallax.com/propeller-c-tutorials
*/
#include "simpletools.h"
#include "propeller.h" // Include simple tools
#include "fdserial.h"
#define RmotorPin 17
#define DmotorPin 19
#define RdirPin 18
#define DdirPin 20
#define FDRX 0
#define FDTX 1
fdserial *fd;
int b1, b2, b3, b4;
int ck;
int data;
char Buffer[32];
int i;
int main()
{
low(RmotorPin); //<-- set pin as output
low(RdirPin); //<-- default direction
low(DmotorPin);
low(DdirPin);
fd = fdserial_open(FDRX, FDTX, 0, 115200);
clkset(0x6b,5000000); //<-- Not needed, does nothing.
pwm_start(600); //<-- generate a pulse every 600 milliseconds
//pwm_start(20000);
i = 0;
while(1)
{
ck = fdserial_rxCheck(fd); //<-- if we have serial data use it
while(fdserial_rxCheck(fd) > 0)
{
Buffer[i++] = fdserial_rxChar(fd); //<-- Capture one of the four bytes
}
if (i > 0) //<-- we have serial data
{
if (i == 4) //<-- valid serial packet?
data = 'A';
else
data = ' ';
i = 0;
print("%d,%d,%d,%d\n", Buffer[0], Buffer[1], Buffer[2], Buffer[3]);
}
b1 = input(3); //<-- get button input which overrides serial
b2 = input(4);
b3 = input(5);
b4 = input(6);
if (b1 == 1)
data = 'W';
if (b2 == 1)
data = 'N';
if (b3 == 1)
data = 'E';
if(b4 == 1)
data = 'S';
switch(data)
{
case 'W':
high(RdirPin); //<-- set direction before starting motor
pwm_set(RmotorPin,0,500); //<-- turn on motor to 83% - 500/600
if (b1 == 0) //<-- button released
data = ' ';
break;
case 'N':
high(DdirPin);
pwm_set(DmotorPin,1,500);
if (b2 == 0)
data = ' ';
break;
case 'E':
low(RdirPin);
pwm_set(RmotorPin,0,500);
if (b3 == 0)
data = ' ';
break;
case 'S':
low(DdirPin);
pwm_set(DmotorPin,1,500);
if (b4 == 0)
data = ' ';
break;
case 'A':
set_output(RdirPin, Buffer[1]);
set_output(DdirPin, Buffer[3]);
pwm_set(RmotorPin, 0, Buffer[0]);
pwm_set(DmotorPin, 1, Buffer[2]);
break;
default: //<-- no buttons or serial data all stop
pwm_set(RmotorPin,0,50); //<-- set motor speed to 8% - 50/600
pwm_set(DmotorPin,1, 0); //<-- set motor to stop 0% - 0/600
low(RdirPin); //<-- set direction to default
low(DdirPin);
break;
}
pause(250); //<-- wait 250 milliseconds or 1/4 of a second.
}
}
I tried the new program but I don't see anything in the IDE monitor and n movement in motors when I press buttons on the hand controller but the switches on the propeller do illicit reaction on the motors as needed.
There could be few things wrong with serial data. This is where a Serial Dongle comes in handy. You can test with hardware that works.
1) The Arduino is 5v and the Propeller is 3.3v which means you need a level shifter otherwise you will damage the Propeller.
2) The wrong pins are being used. What pin is 2 and 3 now?
3) Tx and Rx are reversed. Are they saying this is the Tx pin or that the Tx pin goes here or what?
I see you are using soft serial to output to the Propeller. The documentation shows SoftwareSerial softserial(Rx, Tx), but your code is showing just the opposite. "SoftwareSerial serial_flip(txpin,rxpin);".
Maybe you need another flip board to replace the Nano board you have. The code would be easy enough to port over to it and would remove the 5v to 3.3v issue.
I am using a 3k ohm resistor in series with the arduino tx pin, The pin D3 is the softserial tx pin on the arduino. I rechecked and the rx=2 and tx = 3 and softwareserial serial_flip(rx,tx). This is my current sketch.
But as before I receive no information from the rx pin to the serial monitor or to the motors and I do have some readable data to the rx pin from the arduino. perhaps it is time to convert the arduino sketch to a propeller but I may need some help.
Lets backup up a little here. We need to asses the serial problem first.
Here is a simple program that will take data in from a serial pin and output it to the monitor on the flip. It will also take data from the flip and send it out the serial pin.
#include "simpletools.h"
#include "fdserial.h"
fdserial *trm;
terminal *dft;
int c;
int main()
{
simpleterm_close();
trm = fdserial_open(31, 30, 0, 115200);
dft = fdserial_open(0, 1, 0, 115200);
pause(1000);
dprint(trm, "Ready\n");
while (1)
{
c = fdserial_rxCheck(trm);
if (c > 0)
fdserial_txChar(dft, c);
c = fdserial_rxCheck(dft);
if (c > 0)
fdserial_txChar(trm, c);
}
fdserial_close(trm);
fdserial_close(dft);
}
I don't have a nano board and there seems to be a couple of suppliers that are different out there but here is a diagram of one.
If you tied pin 1 of the nano to pin 0 of the flip with the resistor it should mirror everything that you send from the nano.
Also you are using pin 2 for receive and 3 for data out which would be connect to pin 0 on the flip. This should work.
Also here is the Arduino program converted to Propeller. The Propeller does not support pull-up on pins but I believe you are using resistors on the switches so this is not needed anyway.
You need to decide what ratio you want to output. Based on the motors you would say 25% power for low, 50% power for medium, and 75% for fast and 100% for all out move.
If your PWM value is say 2000 microseconds then 1000 microseconds is 50% = 1000/2000.
Here is a sample program to drive one motor at the different values:
#include "simpletools.h"
#define PWM1 15
int i;
int main()
{
pwm_start(2000); //<-- 2 milliseconds
i = 4; //<-- set speed
switch (i)
{
case 1:
pwm_set(PWM1, 0, 500); //<-- .5 milliseconds 25%
break;
case 2:
pwm_set(PWM1, 0, 1000); //<-- 1 milliseconds 50%
break;
case 3:
pwm_set(PWM1, 0, 1500); //<-- 1.5 milliseconds 75%
break;
case 4:
pwm_set(PWM1, 0, 2000); //<-- 2 milliseconds 100%
break;
default:
break;
}
while(1)
{
pause(1000);
}
}
Setting "i" to the 4 values generates the follow output shown on the scope. You can see at 1 the pulse is high only 25% of the time and 2 it is 50% and so on.
This only works if you are using the UDN2993 chips.
I will try to add or replace parts of the program(LX50 ver 3) but I still have no transmission to the second flip. I tried to use the serial monitor on the hand controller, I get "value1: 200, value2:0, value3: 0, value4:
value1: 0, value2: 0, value3: 0, value4: 0" after I press the 'w' button on the hand controller. When I press the button the value 1 on the second line reads 200 and rest are zeros. I would like to print the input values of the mount flip.
I am lost. about your post on5/13 4:10:37 I looked at the sketch but I don't know how it works with the serial input which uses a group of buffers. I need to convert the variables to the (pwm_set (600)) since that is the level I am using.
It's not that complicated. You want to drive the motors at some percentage of full power to make the telescope move at the rate you want. The problem is I don't know how fast the motors move at each of those percentages.
So if we drive the UDN2993 at 50% what speed does that look like on the telescope. Is it too fast too slow or just right.
On the flip you are using x/600 for the percentage. On the Arduino they are using x/255 for the percentages.
You can see from the graph of the scope output that the pulse last x percent based on the value you pick.
On the Arduino you picked these values
Mode 1: --> R 100/255 = 39%
Mode 1: --> D 75/255 = 29%
Mode 2: --> R 150/255 = 59%
Mode 2: --> D 100/255 = 39%
Mode 3: --> R 200/255 = 78%
Mode 3: --> D 150/255 = 59%
Mode 4: --> R 250/255 = 98%
Mode 4: --> D 200/255 = 78%
If these percentage of full power are what you want then you just build the same percentages on the flip.
To match the Arduino program you would start pwm at 255 for your value.
pwm_start(255); //<-- repeat every 255 microseconds.
Now the output from the pwm_set(x, 0, 100); //<-- 100/255 or 39% of full power.
Now 0 - 255 doesn't give you a lot of choices for the percentage you want to drive the motors so if you want to use 600 then you just need to multiply to get the percentage you want.
100 = 39% = .39 X 600 = 234
75 = 29% = .29 X 600 = 174
We can see that the difference is 255/600 = 2.35 which would be the factor you need to multiply by to get the same percentages.
100 X 2.35 = 235 = 235/600 = 39%
250 X 2.35 = 587 = 587/600 = 98%
Now since we don't want to use floating point math just use 100 times the value or 235 and divide by 100 before you use it.
100 X 235 = 23500/100 = 235.
250 X 235 = 58750/100 = 587.
I am running two flips now but the transmitted signal can be reset in the hand controller to higher values . the pwm_set can be used in the modes, right.
// mode 1
case 1:
switch(directionFlag)
{
// mode 1
case 1:
{
pwm_set(RmotorPin, 0, 100);
pwm_set(DmotorPin, 1, 0);
break;
No function yet and the mount 'flip' is a new one and I have a signal (high going low and back to high, one long then two small and another long) on the P1 pin which is tx pin.
Comments
0 = 0/255 = 0%
100 = 100/255 = 39%
150 = 150/255 = 59%
200 = 200/255 = 78%
250 = 250/255 = 98%
On the Propeller these translate to
0 = 0/600 = 0%
100 = 100/600 = 17%
150 = 150/600 = 25%
200 = 200/600 = 33%
250 = 250/600 = 42%
Mike
1) The Arduino is 5v and the Propeller is 3.3v which means you need a level shifter otherwise you will damage the Propeller.
2) The wrong pins are being used. What pin is 2 and 3 now?
3) Tx and Rx are reversed. Are they saying this is the Tx pin or that the Tx pin goes here or what?
I see you are using soft serial to output to the Propeller. The documentation shows SoftwareSerial softserial(Rx, Tx), but your code is showing just the opposite. "SoftwareSerial serial_flip(txpin,rxpin);".
Maybe you need another flip board to replace the Nano board you have. The code would be easy enough to port over to it and would remove the 5v to 3.3v issue.
Mike
Mike
Mike
Here is a simple program that will take data in from a serial pin and output it to the monitor on the flip. It will also take data from the flip and send it out the serial pin.
I don't have a nano board and there seems to be a couple of suppliers that are different out there but here is a diagram of one.
If you tied pin 1 of the nano to pin 0 of the flip with the resistor it should mirror everything that you send from the nano.
Also you are using pin 2 for receive and 3 for data out which would be connect to pin 0 on the flip. This should work.
Also here is the Arduino program converted to Propeller. The Propeller does not support pull-up on pins but I believe you are using resistors on the switches so this is not needed anyway.
Mike
Mike
Mike
If your PWM value is say 2000 microseconds then 1000 microseconds is 50% = 1000/2000.
Here is a sample program to drive one motor at the different values:
Setting "i" to the 4 values generates the follow output shown on the scope. You can see at 1 the pulse is high only 25% of the time and 2 it is 50% and so on.
This only works if you are using the UDN2993 chips.
Mike
value1: 0, value2: 0, value3: 0, value4: 0" after I press the 'w' button on the hand controller. When I press the button the value 1 on the second line reads 200 and rest are zeros. I would like to print the input values of the mount flip.
If you don't see anything then the serial isn't working.
Mike
So if we drive the UDN2993 at 50% what speed does that look like on the telescope. Is it too fast too slow or just right.
On the flip you are using x/600 for the percentage. On the Arduino they are using x/255 for the percentages.
You can see from the graph of the scope output that the pulse last x percent based on the value you pick.
On the Arduino you picked these values
Mode 1: --> R 100/255 = 39%
Mode 1: --> D 75/255 = 29%
Mode 2: --> R 150/255 = 59%
Mode 2: --> D 100/255 = 39%
Mode 3: --> R 200/255 = 78%
Mode 3: --> D 150/255 = 59%
Mode 4: --> R 250/255 = 98%
Mode 4: --> D 200/255 = 78%
If these percentage of full power are what you want then you just build the same percentages on the flip.
To match the Arduino program you would start pwm at 255 for your value.
pwm_start(255); //<-- repeat every 255 microseconds.
Now the output from the pwm_set(x, 0, 100); //<-- 100/255 or 39% of full power.
Now 0 - 255 doesn't give you a lot of choices for the percentage you want to drive the motors so if you want to use 600 then you just need to multiply to get the percentage you want.
100 = 39% = .39 X 600 = 234
75 = 29% = .29 X 600 = 174
We can see that the difference is 255/600 = 2.35 which would be the factor you need to multiply by to get the same percentages.
100 X 2.35 = 235 = 235/600 = 39%
250 X 2.35 = 587 = 587/600 = 98%
Now since we don't want to use floating point math just use 100 times the value or 235 and divide by 100 before you use it.
100 X 235 = 23500/100 = 235.
250 X 235 = 58750/100 = 587.
Mike
Mike
Is serial data now working?
Mike
case 1:
switch(directionFlag)
{
// mode 1
case 1:
{
pwm_set(RmotorPin, 0, 100);
pwm_set(DmotorPin, 1, 0);
break;
No function yet and the mount 'flip' is a new one and I have a signal (high going low and back to high, one long then two small and another long) on the P1 pin which is tx pin.
Mike
Mike