Shop OBEX P1 Docs P2 Docs Learn Events
Flip and propellerC language; RESOLVED - Page 3 — Parallax Forums

Flip and propellerC language; RESOLVED

135678

Comments

  • msrobotsmsrobots Posts: 3,709
    edited 2020-02-17 21:18
    The propeller is usually a I2C master at pins 28/29, but here might be a Ic2 slave program in the OBEX.

    I would use serial communication between Arduino and P1 you could send a command and wait for a response. P1 can do serial on any pins (except 28/29 used for I2C EEPROM.

    Be aware that the Propeller is 3.3 volt, if your Arduino is 5V you need to put a resistor between TX from Arduino and RX on the flip side.


    == in C is used for comparison
    = in C is the Assignment Operator

    So = in C would be the equivalent of := in Spin.

    Enjoy!

    Mike
  • Lets go back to" master" mode. I can rewrite the I2C codes to make the arduino a slave but I need to convert the arduino"4" address into a 7bit address, is that a binary or a hexadecimal number.
  • Is 0x4 the same as the "4" address in arduino's I2C between two arduinos. I know that when communicating with other devices arduino uses a 7 bit hexadecimal number.
  • Here is what I am doing. Arduino transmits a start signal with a slave address and then the slave looks for its ID and if it see's its name it sends a ready bit and then it accepts the four bytes from the master. Can I use a polling statement with the flip after starting a" I2C COG" and when it reads a start bit, have it stop the COG 0 to transmit the four bytes to the output pins and when the I2C line is released restart the COG 0.
  • I don't think the Parallax library is setup to be a slave. A new library would have to be developed to make the flip a slave and not the master.

    It would be far simpler to use serial instead of i2c.

    Mike
  • how would I set up the flip to read the arduino when it transmits it's signal(refer to post on 2-13 at 13:28 ),usxing the I2C cog. Please help, the hand controller is already completed.


    Brien
  • bbrienbbrien Posts: 561
    edited 2020-03-01 18:13
    Ok, let's talk more about "Serial". How do I set up for a transmission of motor control from one arduino to a propeller using prop C. As before the arduino is initiating the communication . All I ever see is printing info. I have looked at fdserial.h source code and looks complicated. I only need one-way transfer of bytes as in i2c. the arduino supplies the signal as 4 bytes of data and the "flip" receives the four bytes and applies to the output. I need something short and simple and sweet. I don't want to design and build new boards.
  • Let's backup a bit here. I'm a little late to the party.

    You are trying to move two motors that are attached to your telescope. These motors are controlled by a DC motor controller UDN2993. By pulsing this motor controller you can get the telescope to move in the North, South, West and East direction.

    I have an application that does the same thing shown in this YouTube video DC Motor Controller.

    Mike
  • Welcome to my party. Please read the last four or five posts and maybe you can help me, I am trying to use a i2c system to control a mount . The hand controller is using an arduino to generate a set of pulses. The mount uses a propeller to receive those pulses and send them to the motors. I need to know how to receive the four bytes of data from the arduino. I want to go in one direction;arduino to propeller.The coding for the arduino is about 4900 bytes and uses multiple switch statements and trying to code for the flip would be worse,
  • I see that the Arduino can act as an i2c master or slave. The propeller can only be a master. There is no slave code.

    Serial is the universal answer as the propeller can do both directions and on any pins unlike the Arduino unless you use soft serial.

    Do understand what the Arduino is doing as it looks to me that it can generate the pulses to drive the motor and the Propeller is just over kill.

    Mike
  • bbrienbbrien Posts: 561
    edited 2020-03-02 02:38
    Not exactly overkill as the hand controller is only responsible for the speed slewing at four different speeds. The mount brain takes care of the guide camera and R.A. tracking. hence the need for I2C. I'm thinking that a separate cog can poll and (pseudo) request the continuous stream of data as long as the arduino is sending. I thought of trying serial but it loooks like it has too many steps and would add too much to my existing sketch compared to arduino.
  • Here is the code to do serial receive on pins 6 and 7 of the Propeller:
    #include "simpletools.h"
    #include "fdserial.h"
    
    #define SRX 6
    #define STX 7
    
    fdserial *serial;
    char Data;
    
    
    int main()
    {
      serial = fdserial_open(SRX, STX, 0, 115200);
      
      while(1)
      {
        Data = fdserial_rxChar(serial);
        printi("Charater: %c\n", Data);
      }  
    }
    
    Very simple to do but hard to get working correctly. One of the problems is the Uno is a 5 Volt device and the Propeller is a 3.3 Volt device. You can not hook the pins from the Uno to the Propeller directly otherwise you will burn out the Propeller.

    Mike
  • bbrienbbrien Posts: 561
    edited 2020-03-02 18:32
    I know , I will use a voltage divider in the serial lines of the micro if I can find them, I think I can use tx0 and rx1. Oh well back to the cookbook.
  • kwinnkwinn Posts: 8,697
    If you have a 0-5v serial data signal that you want to go to a Propeller chip then you can use a 10K series resistor between the 5V TX pin and the 3.3V RX pin of the propeller if the distance between them is not too great.
  • About 5-6ft between the hand controller and the mount with coiled telephone cable.
  • iseries wrote: »
    Here is the code to do serial receive on pins 6 and 7 of the Propeller:
    #include "simpletools.h"
    #include "fdserial.h"
    
    #define SRX 6
    #define STX 7
    
    fdserial *serial;
    char Data;
    
    
    int main()
    {
      serial = fdserial_open(SRX, STX, 0, 115200);
      
      while(1)
      {
        Data = fdserial_rxChar(serial);
        printi("Charater: %c\n", Data);
      }  
    }
    
    Very simple to do but hard to get working correctly. One of the problems is the Uno is a 5 Volt device and the Propeller is a 3.3 Volt device. You can not hook the pins from the Uno to the Propeller directly otherwise you will burn out the Propeller.

    Mike

    Does this bring the data to the output or only to a monitor.
  • This receives one piece of data at a time and then outputs it to the monitor(Serial.println() on Arduino). You would need to add code to process the Data byte and do something with it.
      while(1)
      {
        Data = fdserial_rxChar(serial);
        switch (Data)
        {
          case 'N': Motor1_Forward();
            break;
          case 'S': Motor1_Reverse();
            break;
          case 'W': Motor2_Forward();
            break;
          case 'E': Motor2_Reverse();
            break;
          default:
            Motor1_Stop();
            Motor2_Stop();
        }
        printi("Charater: %c\n", Data);
      }
    
    Mike
  • I assume this is for the propeller to read and then output to the outputs; not for the arduino.
  • Right, this is propeller code using the full duplex serial library. The printi is an integer only version of print to save memory. You could just use print().

    The Arduino code would be:
    #include <arduino>
    
    void setup() {
      Serial.begin(115200);
      
    }
    
    void loop() {
      if (Serial.available() > 0)
      {
        char c = Serial.read();
        switch (c)
        {
          case 'N': Motor1_forward();
            break;
          case 'S': Motor1_backward();
            break;
          case 'W': Motor2_forward();
            break;
          case 'E': Motor2_backward();
            break;
          default:
            Motor1_stop();
            Motor2_stop();
        }
      }
    }
    

    Mike
  • Now , the hand controller is using an arduino and the existing com code is
    Wire.beginTransmission(address);
             Wire.write(RmotorPinI2C);
             Wire.write(RdirPinI2C);
             Wire.write(DmotorPinI2C);
             Wire.write(DdirPinI2C);
             Wire.endTransmission();
    
    How do I set up code for the propeller; maybe use ( Serial.send and or Serial.Write).
  • Since you will define the serial pins an address is not needed. So you would use Serial.write(RmotorPinI2C);

    Somewhere RmotorPinI2C is defined as an 8 bit value along with the reset. On sets the motor and the other the direction the motor moves in....

    Mike
  • Tomorrow I will rewrite the codes with this in mind. Hopefully this will work. thanks
  • bbrienbbrien Posts: 561
    edited 2020-03-11 17:46
    Serial .send from arduino will be
                                                                  Serial.write(RmotorPin);
                                                                  Serial.write(RdirPin);
                                                                  Serial.write(DmotorPin);
                                                                  Serial.write(DdirPin);
    
    These variables all use 1 byte of storage each. If I am right the "char" uses 2 bytes. Does this matter in the quote below.
    iseries wrote: »
    Right, this is propeller code using the full duplex serial library. The printi is an integer only version of print to save memory. You could just use print().

    The Arduino code would be:
    #include <arduino>
    
    void setup() {
      Serial.begin(115200);
      
    }
    
    void loop() {
      if (Serial.available() > 0)
      {
        char c = Serial.read();
        switch (c)
        {
          case 'N': Motor1_forward();
            break;
          case 'S': Motor1_backward();
            break;
          case 'W': Motor2_forward();
            break;
          case 'E': Motor2_backward();
            break;
          default:
            Motor1_stop();
            Motor2_stop();
        }
      }
    }
    

    Mike

  • Character and byte use 1 byte unless you are in a double byte environment such as windows then character uses two bytes of space. Arduino is a single byte system so it will only use 1 byte. On Arduino byte is unsigned and char is signed.

    Mike
  • bbrienbbrien Posts: 561
    edited 2020-03-12 20:49
    Somebody missed an important fact and that is the receiving end is a propeller. I want to launch a second core to be the serial receiver and its supposed to receive the four bytes from the arduino. I am planning to take the data(RmotorPin,DmotorPin, RdirPin,andDdirPin) and assign to the motor outputs, can this be done and how.
  • kwinnkwinn Posts: 8,697
    Yes, it can be done, however C is not my cup of tea so I cannot provide the code to accomplish that. If I were doing that it would be in spin and/or assembly. Probably by adding a bit of assembly code to the serial object.
  • bbrienbbrien Posts: 561
    edited 2020-03-13 18:15
    I tried to use"void Serial.send in the top portion of the work page and got a error,
    #include "simpletools.h"
             #include "propeller.h"
             void Serial.send;        //<<--------<<<
             int main() 
              {
                clkset(0x6b,5000000);
                int mask = 0xff0000;
                int freq = CLKFREQ>>1;
                DIRA = mask;
    
                int button1 = input(3);
                int button2 = input(4);
                int button3 = input(5);
                int button4 = input(6);
                 {
                   cog_run(Serial.send);
                 }
                 void (Serial.send)
                 {
                  while(1) 
                   {  
                     Serial.,read( 17,0,RmotorPin);
    
    how do I fix.
  • Only Arduino has Serial.send.

    On the propeller you would use fdserial.
    #include "simpletools.h"
    #include "fdserial.h"
    
    void getData(void *);
    
    #define SRx 0
    #define STx 1
    
    fdserial *fd;
    
    
    int main()
    {
      cognew(&getData, 40);
      
      while(1)
      {
        // Add main loop code here.
        
      }  
    }
    
    
    void getData(void *par)
    {
      char data;
      
      fd = fdserial_open(SRx, STx, 0, 115200);
      
      while (1)
      {
        data = fdserial_rxChar(fd);
        switch (data)
        {
          case 'N':
            break;
          case 'S':
            break;
          case 'W':
            break;
          case 'E':
            break;
          default:
            break;
        }      
      }    
    }
    

    Mike
  • bbrienbbrien Posts: 561
    edited 2020-03-15 18:00
    Under the #define SRx 0 and STx 1, can I use any other pins and are they set in the "int mask". Also do I add the cog new to the end of the main loop or to the beginning of the main loop?
  • SRx and STx are whatever pins you use to send the serial data over. SRx is the receive pin number and STx is the transmit pin back to the Arduino.

    Mike
Sign In or Register to comment.