io control

There are pins on the Basic at the bottom of the robot and the Atom at the end. You can use io control to set the high and low levels of the pins and control tools such as pumps (the pin number can be found on the pin labels attached to the Basic and Atom pins, and the input and output are shared).

M5Stack-basic io control (m5)

Set the output io high and low levels

SetBasicOut(byte pin_number, byte pin_signal)
Return value: None
Parameter description: Parameter 1: Pin number (basic output pin number), Parameter 2: State (0--low level, 1--high level)
Case:
mc.SetBasicOut(2, 1); Thread.Sleep(100); mc.SetBasicOut(5, 1); Thread.Sleep(100);

Get input io status

GetBasicIn(byte pin_number)
Return value: pin status (0--low level, 1--high level)
Parameter description: pin number (basic input pin number)
Example: Set output pin 2 to high level
Console.WriteLine(mc.GetBasicIn(35)); Thread.Sleep(100); Console.WriteLine(mc.GetBasicIn(36)); Thread.Sleep(100);

Atom io control

Note: 320m5 does not have atom io, so this module API is not needed

Set the output io high and low levels

SetDigitalOut(byte pin_number, byte pin_signal)
Return value: None
Parameter description: Parameter 1: pin number (atom output pin number), parameter 2: state (0--low level, 1--high level)
Case:

mc.SetDigitalOut(23, 0);
Thread.Sleep(100);
mc.SetDigitalOut(33, 0);
Thread.Sleep(100);

Get input io status

GetDigitalIn(byte pin_number)
Return value: pin status (0--low level, 1--high level)
Parameter description: pin number (atom input pin number)
Example:

Console.WriteLine(mc.GetDigitalIn(19));
Thread.Sleep(100);
Console.WriteLine(mc.GetDigitalIn(22));
Thread.Sleep(100);

Complete use case

using System;
using System.Threading;

namespace Mycobot.csharp
{
    class Test
    {
        static void Main(string[] args)
        {
            MyCobot mc = new MyCobot("COM57");//Raspberry Pi Robotic Arm Serial Port Name:/dev/ttyAMA0
            mc.Open();
            Thread.Sleep(5000);//After Windows opens the serial port, you need to wait for 5 seconds, and the basic button at the bottom of Windows will restart when it opens the serial port.

            //set basic output io
            /*mc.SetBasicOut(2, 1);
            Thread.Sleep(100);
            mc.SetBasicOut(5, 1);
            Thread.Sleep(100);
            mc.SetBasicOut(26, 1);
            Thread.Sleep(100);*/

            //get basic input io
            Console.WriteLine(mc.GetBasicIn(35));
            Thread.Sleep(100);
            Console.WriteLine(mc.GetBasicIn(36));
            Thread.Sleep(100);

            //set atom output io
            /*mc.SetDigitalOut(23, 0);
            Thread.Sleep(100);
            mc.SetDigitalOut(33, 0);
            Thread.Sleep(100);*/

            //get m5 input io
            /*Console.WriteLine(mc.GetDigitalIn(19));
            Thread.Sleep(100);
            Console.WriteLine(mc.GetDigitalIn(22));
            Thread.Sleep(100);*/

            mc.Close();
        }
    }
}

results matching ""

    No results matching ""