Getting Started with Micro:bit for a Simple Drawing Machine

Micro:bit is a fantastic entry point into the world of coding and electronics, especially for those eager to dive into DIY projects. If you’re curious about how to control movement with code, creating a simple drawing machine is an excellent project to start with. Before we begin, it’s highly recommended to watch some introductory tutorials on YouTube to grasp the basics of Micro:bit and how its code blocks function. A great resource is this video from Sparkfun, which offers a much clearer explanation for Micro:bit beginners than we could provide here. Take some time to watch it to familiarize yourself with the fundamentals.

https://www.youtube.com/watch?v=kaNtg1HGXbY

Once you’re feeling more comfortable with the basics, let’s explore how to program your Micro:bit to operate a drawing machine. This setup can easily be adapted to control a 3d Printed Pen mechanism, allowing for precise and programmable drawings. Here’s a step-by-step guide to get you started:

First, navigate to https://makecode.microbit.org/# in your web browser. This is the platform where you’ll write the code for your Micro:bit using a visual block editor. Click on “New Project” to begin.

Within the MakeCode editor, you’ll see a ‘forever’ block. This block is crucial as any code placed inside it will run continuously as long as the Micro:bit is powered. Drag two ‘servo write pin’ blocks into the ‘forever’ block. These blocks are essential for controlling servo motors, which will drive the movement of your drawing mechanism. For this example, we will use Pin8 and Pin12 to connect to our servo motors. These pins will act as the output (OUT) pins to send signals to the motors.

Now, to control the range of motion of the servos based on input, we need to use a ‘map’ block. Place a ‘map’ block in the section of each ‘servo write pin’ block where you would normally input a write value. The ‘map’ block is incredibly useful for translating one range of values to another. In our case, we want to read analog input from potentiometers (or joysticks) connected to Pin1 and Pin2. These analog inputs will provide values ranging from 0 to 1023, depending on the joystick’s position.

Insert ‘read analog pin’ blocks into the ‘input’ section of each ‘map’ block. Select Pin1 for the first ‘map’ block and Pin2 for the second, as shown in the example diagram. The ‘read analog pin’ blocks will detect the voltage levels from Pin1 and Pin2, representing the joystick’s position.

The ‘map’ block will then convert the input range of 0-1023 (from the joystick) to an output range of 0-180. This output range (0 to 180 degrees) corresponds to the typical range of motion for a servo motor. Therefore, as you move the joystick, the ‘map’ block translates this movement into corresponding servo positions, controlling the direction and speed of the motors which in turn can move your 3d printed pen.

That’s essentially all the code you need! It’s a surprisingly simple setup to get basic control over servo motors using Micro:bit and MakeCode.

Once you’ve completed the coding, it’s time to upload your program to the Micro:bit. Click the ‘Download’ button located at the bottom left corner of the MakeCode interface. This action will download the code file. Connect your Micro:bit to your computer using a micro USB cable. Open your computer’s file explorer; the Micro:bit should appear as a removable drive. Locate the downloaded code file (it will likely be in your ‘Downloads’ folder) and simply drag and drop it onto the Micro:bit drive. The Micro:bit will then flash the code onto its system.

After the code is uploaded, it will run every time you power up the Micro:bit. You can power it using the same micro USB cable connected to your computer or an external power supply. Now you have a Micro:bit programmed to control a basic drawing machine, potentially utilizing a 3d printed pen holder for customized creations.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *