Controlling motion is a primary requirement when it comes to building physical IoT system. Learn how to read values from Analog to digital converters while controllong stepper actions to build your internet controlled machines. View Source
- Basics of what an Analog to Digital and vice versa conversion means.
- Interaction with hardware such as reading digital input and output.
- Controlling output of the actuators and getting feedback.
The project consists of an emulated Raspberry Pi connected to digital input/output and a temperature/humidity sensor.
IoT is the system of system, which allows connecting numbers of sensors, actuators, and detectors which all are uniquely addressable and controllable over the network protocols. All the controllable devices in a system fall under the Actuators category.
An Actuator can be defined as a device that converts energy (in terms of robotics, that energy tends to be electrical) into physical motion. For instance, Stepper Motor or Hydraulic system.
We have a wide family of controllable devices (Actuators). Most commonly used actuators in applications these days are stepper motor, servo motor, DC motors and AC motors. Internet of Things will help us achieve the next industrial boom by allowing to control these devices remotely and intelligently. The major difference between the Internet of Things and the traditional controller is that the new generation of controllers are smart and connected. Connectivity between the cloud and machines will enable us to combine the data, analyze the events, improve the action and manipulate objects in the real world. Choosing a perfect motor for the mechanical application is always an important task.
An Analog to digital converter devices converts an analog value such as voltage to a digital output (regarding binary digit). A2D converters are essential components for interacting with the physical world and digital microprocessor. While most of the event in the real world always happens on analog domain such as displacement, acceleration, fall, the microprocessor could only understand digital values in binary format. A2D converters help bridge this gap.
This is just reverse of what an A2D converter is, i.e. converting digital values to their physical counterpart. For example, motion of a stepper motor or a voltage controlled relay is the classic example of D2A converter.
In this project, we will focus on 3 elements of robotics :
- Analog to digital converter (A2D I2C sensor)
- Digital to Analog conversion (stepper motor)
- Digital Input / Output using GPIO.
Let’s get started. Say Hello! To the internet of Motion with IoTIFY.
A stepper motor or a step motor or a stepping motor is a brushless DC motor, which works on a principle of electromagnetism, that rotates into discrete step angles and makes a complete rotation.
DC motor starts rotating just by applying DC power source to the terminals, but in a case of a stepper motor, it runs on a train of pulses (Square Wave pulses). Each pulse is making the shaft move through a fixed angle.
How stepper motor works?
The below animation shows the working of 4 phase unipolar stepper motor.
It is a brushless DC motor and as it is not having any feedback unlike servo motor so, can be the open loop controllable electronic device. It generally consists of the permanent magnet surrounded by a stator.
As you activate the windings step by step in a particular order and let the current flow through them, it magnetizes the stator creating electromagnetic poles respectively and that will cause particular angular rotation.
Let’s get it started with IoTify.
Signup with iotify.io if you haven’t yet. The free account will have sufficient credits to run this project. Once you are logged into the IoTIFY main application, go to the virtual lab and click on the Hello Motor project.
Provide a unique name for your project. Then simply click launch.
The project takes 3-5 minutes to launch. The project state will automatically change to running once it is ready. You could then simply click the Open button and it will launch a new window with the Workspace of the project.
The webview has a stepper motor, 4 knobs, few switches, and LEDs.All of these internally connected to an emulated raspberry pi 2, so that you can interact with the corresponding peripheral from the terminal by the programming.
The project contains a stepper motor connected to raspberry pi GPIO via driver IC ( DRV8834 By texas Instruments) The driver IC is connected via GPIOs.
The 4 knobs, Whose output is an analog voltage, are connected to an analog-to-digital converter (ADS1115 texas Instruments), Which is connected to emulated pi via I2C (Inter-Integrated Circuit) as we are not having any analog GPIO in our raspberry Pi. You can read the voltage rating by reading from the ADC via I2C.
The web view contains the LEDs and Switches that are connected directly to the Raspberry pi GPIO.
Now, below fig. Shows the Physical connection of stepper motor with raspberry pi (Here we have used DRV8834 Texas Instruments IC as a stepper motor driver).
Open a console terminal to get an ssh access. The source code for the project is already downloaded in hello-motor directory. Here we have two python scripts – one for the motor and one for the ADC converter.
The a2d.py script in hello-motor directory continually polls each of the 4 analog input of ADC. Type following command in your console and you can see the analog voltage values.
Now, if you go to the webview and try to move any of the 4 knobs, you should see in the console output the corresponding voltage values are changing.
What is happening here?
The voltage knobs are simulating 4 analog channels and software is reading values of those channels via A2D converter. Those 4 channels could represent any 4 analog values such as tilt values at a drone wings or tyre pressure of 4 tyres. The software continously monitors the analog values and based upon that it takes certain actions.
Let’s move to the stepper motor. Now, run the motor.py python script as root user in the console. It will interact with emulated motor driver IC, which then moves the motor in the webview.
You can see the motor is rotating as we have both red mark on the stepper motor and a numeric value of the rotation angle.
Stepper motor executes rotation in “steps” where a step corresponds to a fixed amount of rotation; In typical embedded applications, we use motors with 200 steps per revolution, Which means that one step corresponds to a 1.8 degree rotation. That’s why we chose our motor to have 200 steps per revolution.
To change the steps, Open the motor.py script and here you can see, it executes a rotation of a fixed number of steps given by “steps” variable.
steps = -10
Of Course, you can change the value of the “steps” variable and re-execute the script and see the motor is rotating by a different amount. Motor will rotate clockwise if the number of steps is positive, and counter-clockwise if the number of steps is negative.
Here, also you can find some declaration at the beginning of the script. It shows which Rpi GPIOs are used to connect different pins of DRV8834 IC (Motor driver IC). So that you can have the idea how Driver IC is connected to the raspberry Pi GPIO. The Driver IC can work in both modes i.e. Indexer Mode and phase/enable mode.
The motor.py script is for both the modes, you can change the mode by just changing the “indexer_mode” variable value (True or False).By Default it is in Indexer mode because it’s easier to use. You have the privilege to modify the code and make it work as per your application.
We have shown you the basics of controlling a mechanical system with IoTIFY. Further ideas could be
Use one of the input channel to indicate water level and use motor to turn on/off the valve.
Create a 2-d moving robot where each of the voltage knobs specify the direction of motion and final angle of motor decides the way robot should move.
Do you love this project? Tell us what you think at the discussion forum, or share with your colleagues by clicking social icons below.