Announcement

Collapse
No announcement yet.

[Draft] Arduino - Control DC Motor using DCMotor Controller - PES-2604

Collapse
X
Collapse

  • [Draft] Arduino - Control DC Motor using DCMotor Controller - PES-2604

    This tutorial is for the upcoming PhpocExpansion library

    PES-2606 is an easy-to-use RS-232 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS-232. Especially, Arduino does NOT use UART pins to communicate with RS-232 expansion. Therefore, users can use Arduino UART pins for other purposes. Moreover, A single Arduino Uno/Mega can communicate with multiple RS-232 expansion boards (up to 14) without using Arduino UART pins.

    Library and example for the RS-232 expansion board are part of of PhpocExpansion library for Arduino. The library reference is available here

    This tutorial shows how to use RS-232 expansion board with an example of PhpocExpansion library for Arduino.


    Application





    Testing

    RS-232 Expansion Board is designed to let Arduino exchange data with serial device via RS-232. For testing, we can use PC or laptop as a serial device. Although most of PC and laptop does not have RS-232 COM port, we still can do the test by using RS-232 to USB cable.




    Hardware Required

    Note that: in the test, we use two cables: one is USB cable that connects PC to Arduino, the other cable is RS-232 to USB cable that connects PC to RS-232 expansion board for testing. These cables connect to PC with different COM ports.
    You can check these COM Port by accessing "Device Manager" on your PC. It looks like below image.



    Note that the COM port number is depending on each PC.



    Wiring
    • Stack PHPoC Shield or PHPoC WiFi Shield on Arduino.
    • Stack RS-232 expansion board PES-2606 on PHPoC Shield or PHPoC WiFi Shield.
    • Connect Arduino to PC via usb cable.
    • Connect RS-232 to USB cable to expansion board and your PC.






    Install Arduino IDE

    If you have not install Arduino IDE yet, please download and install Arduino IDE .





    Install Library
    • Run Arduino IDE.
    • Navigate to Sketch > Include Library > Manage Libraries

    • Search "PhpocExpansion" on search bar of the Library Manager.

    • Select the PhpocExpansion library and press the [Install] button.

    • Restart Arduino IDE for the next step.



    Source Code
    • Run Arduino IDE.
    • Open "ExpansionSerialRS232" example.
    • Compile the example code and uploads to Arduino by clicking "Upload" button on Arduino IDE.
    • Run a Serial software such as TeraTerm, connect to COM port corresponding to RS-232 to Serial cable.
    • Open "Serial Monitor" tool on Arduino IDE.
    • Send some data from TeraTerm to RS-232 Expansion Board by typing some characters in TeraTerm.
    • We can see that, data is shown on both TeraTerm and Serial Monitor.

    Code Explanation

    This code does:
    • Reads data from RS-232 expansion boards.
    • Sends back the received data to RS-232 expansion boards and prints the received to Serial Monitor.




    At the beginning
    • We need to create a ExpansionSerial object:
      Code:
      ExpansionSerial rs232(spcId);
      Where spcId is address of expansion board that are set via dip switch on expansion board. By using the different spcId, we can stack multiple expansion board on a single Arduino Uno or Mega.
      You can change it and map it to the below to know the value.

    • We need to create a buffer to keep the received data:
      Code:
      byte rwbuf[BUFFER_SIZE];



    Note that: RS-232 expansion board is one of the expansion boards. List of expansion for Arduino is available here



    In setup() function
    • Phpoc.begin() and Expansion.begin() functions must be used to initial PHPoC [WiFi] Shield and expansion board, repectively.
    • Serial.println(in0.getName()) function is used optionally to get name of expansion board and print it to serial.
    • rs232.begin(F("115200N81N")) function is used to set baud-rate, parity, data bit, stop bit and flow control to 115200, none, 8 bit, 1 bit and no flow control, respectively.


    In loop() function

    There are some functions are used.
    • rs232.available(): get the size of received data in the receiving buffer of RS-232 expansion board.
    • rs232.availableForWrite(): get the size of free space in the sending buffer of RS-232 expansion board.
    • rs232.readBytes(rwbuf, rwlen): receive data from the receiving buffer of RS-232 expansion board and save it to the application buffer.
    • rs232.write(rwbuf, rwlen): send data from the application buffer to the sending buffer of RS-232 expansion board.


    Data is read from the receiving buffer of RS-232 expansion board and save to application buffer, and then write to the sending buffer of RS-232 expansion board.



    Firstly, we get the size of received data in receiving buffer of RS-232 expansion board.
    Code:
    // get the size of the received data in the receiving buffer of RS-232 expansion board
    int rxlen = rs232.available();

    If data is available in the receiving buffer of RS-232 expansion board, get the size of free space in the sending buffer of RS-232 expansion board.
    Code:
    // read and write length
    int rwlen;
    
    // get the size of free space in the sending buffer of RS-232 expansion board
    int txfree = rs232.availableForWrite();

    If we read an amount of data that exceed capacity of application buffer, application buffer will be overflowed and data is lost.
    Therefore, before reading data, we need to make sure that the the reading data does not exceed the application buffer capacity.
    Code:
    // check to make sure that read data does not exceed size of application buffer
    rwlen = min(rxlen, BUFFER_SIZE);

    All data that stored in application buffer will be written to the sending buffer of of RS-232 expansion board. If we write an amount of data that exceed the free space of the sending buffer of RS-232 expansion board, the sending buffer of RS-232 expansion board will be overflowed and data is lost. Therefore, before reading data and store data to application buffer, we need to make sure that the the reading data does not exceed the free space of the sending buffer of RS-232 expansion board.
    Code:
    // check to make sure that write data does not exceed free space in the sending buffer of RS-232 expansion board
    rwlen = min(rwlen, txfree);

    Reading data from the receiving buffer of RS-232 expansion board and save to application buffer.
    Code:
    // receive data from the receiving buffer of RS-232 expansion board and save it to the application buffer
    rwlen = rs232.readBytes(rwbuf, rwlen);

    Sending data from the application buffer to the sending buffer of RS-232 expansion board
    Code:
    // send data from the application buffer to the sending buffer of RS-232 expansion board
    rs232.write(rwbuf, rwlen);

    Printing data to Serial Monitor of Arduino IDE
    Code:
    // print data to serial monitor of Arduino IDE
    Serial.write(rwbuf, rwlen);

    See Also

    References
    Last edited by support; Today, 02:08 PM.
      Posting comments is disabled.

    Categories

    Collapse

    Article Tags

    Collapse

    Latest Articles

    Collapse

    • [Draft] Arduino - Monitor States of High-voltage Device using Input Expansion Board
      support
      This tutorial is for the upcoming PhpocExpansion library

      PES-2602 is an easy-to-use 4-port Input Expansion Board for Arduino Uno and Mega, which allows Arduino to monitor state of high-voltage device.
      Library and example for the 4-port input expansion board are part of of PhpocExpansion library for Arduino.
      This tutorial shows how to use 4-port input expansion board with an example of PhpocExpansion library for Arduino.


      Hardware Required
      • Arduino Uno
      ...
      09-11-2018, 05:38 PM
    • [Draft] Arduino - Control high-voltage devices using Relay Expansion Board - PES-2601
      support
      This tutorial is for the upcoming PhpocExpansion library

      PES-2601 is an easy-to-use 4-port Relay Expansion Board for Arduino Uno and Mega, which allows Arduino to control high-voltage device on/off .
      Library and example for the 4-port relay expansion board are part of of PhpocExpansion library for Arduino.
      This tutorial shows how to use 4-port relay expansion board with an example of PhpocExpansion library for Arduino.


      Hardware Required
      • Arduino Uno
      ...
      09-11-2018, 04:28 PM
    • [Draft] Arduino - Control DC Motor using DCMotor Controller - PES-2604
      support
      This tutorial is for the upcoming PhpocExpansion library

      PES-2606 is an easy-to-use RS-232 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS-232. Especially, Arduino does NOT use UART pins to communicate with RS-232 expansion. Therefore, users can use Arduino UART pins for other purposes. Moreover, A single Arduino Uno/Mega can communicate with multiple RS-232 expansion boards (up to 14) without using Arduino UART pins.
      ...
      09-11-2018, 01:17 PM
    • [Draft] Arduino - Control Stepper Motor using Stepper Motor Controller - PES-2605
      support
      PES-2605 is an easy-to-use stepper motor controller for Arduino Uno and Mega, which uses micro-stepping method to precisely control stepper motor. Library and example for the stepper motor controller
      09-03-2018, 04:30 PM
    • PHPoC - Configuring Network Information via Web
      support
      This example show how to create an Web app that allows to check and config network information (e.g MAC address, IP addess, ...) remotely via Web browser.


      Hardware
      • PHPoC Blue (+ USB WLAN) or PHPoC Black (+ Ethernet cable)
      • Micro USB to USB Cable (to upload source code to PHPoC Device)


      Quick Steps

      Source code of this example is a part of PHPoC Support Packet (PSP). You need to:...
      02-07-2018, 09:23 AM
    • TCP Client - HTTP GET
      support
      What is HTTP?

      HTTP means HyperText Transfer Protocol. HTTP is the underlying protocol used by the World Wide Web. The protocol defines how messages are formatted and transmitted, and what actions Web servers and browsers should take in response to various commands.
      For example, when you enter a URL in your browser, this actually tells Web browser make an HTTP request to the Web server.

      PHPoC has an embedded web server. However, this example shows PHPoC devices...
      02-02-2018, 06:27 PM
    Working...
    X