It's a loop back program in that you can type on the terminal and it will be sent out or data received is displayed.
Since you Arduino program is sending binary data it will not show up on the terminal because they will be miss interpreted
by the terminal program.
We could modify the Arduino program to send ASCII data and then update the flip program to convert it back to binary for use.
#include "simpletools.h"
#include "fdserial.h"
fdserial *trm;
fdserial *dft;
int c;
int main()
{
simpleterm_close(); //<-- by default this is the terminal program so to use fdserial it must be closed.
trm = fdserial_open(31, 30, 0, 115200); //<-- reopen the terminal USB connection using full duplex terminal.
dft = fdserial_open(0, 1, 0, 115200); //<-- look for serial data coming in on pin 0 and being transmitted on pin 1.
pause(1000);
dprint(trm, "Ready\n");
while (1)
{
c = fdserial_rxCheck(trm); //<-- Check if we received any data from USB terminal
if (c >= 0)
fdserial_txChar(dft, c); //<-- Send it out pin 1 to other unit.
c = fdserial_rxCheck(dft); //<-- Check if we received any data from other unit on pin 0.
if (c >= 0)
fdserial_txChar(trm, c); //<-- Send it out to terminal on USB.
}
fdserial_close(trm); //<-- This code is unreachable but would close the open connection.
fdserial_close(dft);
}
Ok, I had a chance to check the code over and found a error in the code I gave you. One of the problems here is I don't have your setup to test the code with. Anyway I put together some test code and found the serial function doesn't work correctly.
Here is some updated code for the flip side to hopefully receive the serial Arduino data.
while(1)
{
while(fdserial_rxCount(fd) > 0) //<-- check if we have data
{
Buffer[i++] = fdserial_rxChar(fd); //<-- Capture one of the four bytes
pause(5); //<-- wait a bit for more data
}
if (i > 0) //<-- we have serial data
{
if (i == 4)
{
data = 'A';
}
else
data = ' ';
i = 0;
printi("%d,%d,%d,%d\n", Buffer[0], Buffer[1], Buffer[2], Buffer[3]);
}
This should replace the previous code in that section.
#include "simpletools.h"
#include "propeller.h" // Include simple tools
#include "fdserial.h"
void convert(void); //<-- add this
#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)
{
while(fdserial_rxCount(fd) > 0) //<-- check if we have data
{
Buffer[i++] = fdserial_rxChar(fd); //<-- Capture one of the four bytes
pause(5); //<-- wait a bit for more data
}
if (i > 0) //<-- we have serial data
{
if (Buffer[i-1] == '\r') //<-- Change to this
{
convert(); //<-- add this
data = 'A';
}
else
data = ' ';
i = 0;
printi("%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.
}
}
void convert() //<-- add this function
{
int Dp, Dd, Rp, Rd;
sscanf(Buffer, "%d,%d,%d,%d", &Dp, &Dd, &Rp, &Rd);
Buffer[0] = Dp;
Buffer[1] = Dd;
Buffer[2] = Rp;
Buffer[3] = Rd;
Buffer[4] = 0;
}
At this point, all I care is whether or not the two flips talk and understand each other, IE... one way com . I will try the revised code and let you know.
tried the new 'flip' board and the old LX50 ver 3 sketch and still no receive data on theterminal monitor. I do get some info on the (5/10 5:29 post running on the flip(mount). No function on the camera switches using the ver 4 listed here.
Concerning the half duplex serial I am sending data from one "flip to another Flip through a 2Meter cable This is only a one way trip and data consists of a single byte number (x) four,I need to read the incoming bytes and send to a receiving buffer[32]. what do I use. the only thing I can find is"int readDec(text_t *device).
Somebody please help;
I think the Camera switch will not work without pull-up resistors connected to the pins. Propeller does not have a way to use internal pull-ups like the Nano does.
All of my inputs are pulled high with 10k resistors. I have tried 3 different Flips and two are new and still can't get a transfer to the output pins. The tx pin of the first Flip shows a set of pulses that are going low, but they are not continuous. I will try to get a picture.
This can be hard to detect as the pulses for each byte is different and each start with one start bit and two stop bits. It's not a steady stream of bits.
When a button is pressed it generates a serial packet with the 4 values. If the button remains pushed it does nothing. The code removes duplicates and only checks every 50 milliseconds for a change. When a change is detected such as releasing the button it generates a packet with those new values.
That code will not work. The problem is that the fdserial_rxCheck eats the character coming in. I have revised the code to use fdserial_rxCount instead which will tell if a character has been received and then processes all the incoming data. Also the terminal code causes the print() function to fail and lockup the program so that is also removed.
Here is the updated code. The convert function can be used later but for now just ignore it.
/*
Blank Simple Project.c
http://learn.parallax.com/propeller-c-tutorials
*/
#include "simpletools.h"
#include "propeller.h" // Include simple tools
#include "fdserial.h"
void convert(void); //<-- add this
#define RmotorPin 17
#define DmotorPin 16
#define RdirPin 18
#define DdirPin 15
#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)
{
while(fdserial_rxCount(fd) > 0) //<-- check if we have data
{
Buffer[i++] = fdserial_rxChar(fd); //<-- Capture one of the four bytes
pause(5); //<-- wait a bit for more data
}
if (i > 0) //<-- we have serial data
{
if (i == 4)
{
data = 'A';
}
else
data = ' ';
i = 0;
printi("%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.
}
}
void convert() //<-- add this function
{
int Dp, Dd, Rp, Rd;
sscanf(Buffer, "%d,%d,%d,%d", &Dp, &Dd, &Rp, &Rd);
Buffer[0] = Dp;
Buffer[1] = Dd;
Buffer[2] = Rp;
Buffer[3] = Rd;
Buffer[4] = 0;
}
I gave your latest ideas a run for the money but they just don't work. I get no reading from the serial monitor and no operation from the serial input only the guide camera inputs work.
The guide camera is attached to one of the small scopes riding piggy back on the big scope. The guide camera connects to pins(3,4,5,7) and is represented by a bank of four switches. They will connect to the board by way of a 6 pin modular phone jack. The "Black Box is a complete system with switches communicating by serial means.
After thinking about this for a while I think the problem is how the code is being loaded on the flip. On the Arduino you can only load the code, but on the flip there are two ways that the code can be loaded.
Unlike the Arduino Nano the flip uses external EEPROM to save the program to. So when you load code to the flip it is first placed in RAM on the Propeller and then transferred to the EEPROM.
When you program the flip you can choose weather you want to just load the Propeller or save it to EEPROM.
The difference is that if you just load the Propeller it only exist in RAM on the Propeller and once the flip is reset or power cycled that code is lost and the code that was previously placed on EEPROM is loaded instead.
This can come in handy if you have some stable code running on the Propeller and you want to try some new code out but you don't want to change the code that is working on the Propeller. So you load the code to RAM and if it doesn't work you just power cycle the board and the old code is now running again.
On the SimpleIDE you need to use the correct button or option that loads the code on the flip. The run with terminal option only loads to RAM and the code will be lost after reset or power cycle.
You need to use the LED's on the flip connected to pins 26 and 27 and make them flash or turn on when something happens so you know the code is working.
When I load the code to the EEPROM on the flip the com leds blink for a short time and stop and the serial com leds flash when I am connected to the serial monitor and I know that thge loaded code is working because if I depress each in turn I get a response from the motors and the connected leds and if no buttons are pressed the R.A. motor turns at the slow speed. If the serial part of the code works I should have a print out of the Buffers at least and if the buttons on the "hand controller" should activate one of the motors.
My attempts to use the serial communication to pass data from 1 flip to another flip is not going anywhere so I am going to try to use the idea of the spin method" Output := Input pin. I used this method years ago to send a pulse from one devise to a propeller with some success. I used the expression " Output pin = input(8); and received an error"lvalue required as left operand of assignment" . Please show the correct expression or how to add spin to the propeller C language.
I would like to use pins 17 and 16 as pwm pins using spin but I dont quite understand using the ctra and b registers . and also setting the pulse period and duty cycle.
Comments
It's a loop back program in that you can type on the terminal and it will be sent out or data received is displayed.
Since you Arduino program is sending binary data it will not show up on the terminal because they will be miss interpreted
by the terminal program.
We could modify the Arduino program to send ASCII data and then update the flip program to convert it back to binary for use.
Mike
Here is some updated code for the flip side to hopefully receive the serial Arduino data.
This should replace the previous code in that section.
Mike
LX50A
LX50
Mike
Mike
Somebody please help;
Mike
If your not seeing it at the other end then you have the something wired incorrectly. Tx to Tx for example will not work.
Mike
When a button is pressed it generates a serial packet with the 4 values. If the button remains pushed it does nothing. The code removes duplicates and only checks every 50 milliseconds for a change. When a change is detected such as releasing the button it generates a packet with those new values.
Mike
Here is the updated code. The convert function can be used later but for now just ignore it.
Don't get it. The flip is the only thing connected to the motors so how can the guide camera do anything.
Mike
Unlike the Arduino Nano the flip uses external EEPROM to save the program to. So when you load code to the flip it is first placed in RAM on the Propeller and then transferred to the EEPROM.
When you program the flip you can choose weather you want to just load the Propeller or save it to EEPROM.
The difference is that if you just load the Propeller it only exist in RAM on the Propeller and once the flip is reset or power cycled that code is lost and the code that was previously placed on EEPROM is loaded instead.
This can come in handy if you have some stable code running on the Propeller and you want to try some new code out but you don't want to change the code that is working on the Propeller. So you load the code to RAM and if it doesn't work you just power cycle the board and the old code is now running again.
On the SimpleIDE you need to use the correct button or option that loads the code on the flip. The run with terminal option only loads to RAM and the code will be lost after reset or power cycle.
You need to use the LED's on the flip connected to pins 26 and 27 and make them flash or turn on when something happens so you know the code is working.
Mike
I have test the C serial code and it works. You need to show both Master and Slave programs so we can see why it's not working.
Mike