-
PICmicro C Programming Reference
08/31/2023 at 22:47 • 0 commentsBeginner C coders often have difficulty with the C language syntax, especially at or below the early high school level. In order to help the students in my classes, I created and shared a PICmicro C Programming Reference document with them in Google drive.
The order of its contents roughly align with the topic introduced in the introductory programming activities for the CHRP4 and UBMP4, so the contents can be introduced when appropriate during the lessons.
The Google document is freely available for anyone to edit and re-mix, and can easily be modified to incorporate Arduino syntax, or other C-style language. Hopefully some people will find it useful!
-
CHRP4 Programming Activities
05/28/2023 at 00:20 • 0 commentsOne of the best gifts a teacher can receive is time. When deciding what to teach, as well as how to teach it in order to achieve the desired curriculum outcomes, it's incredibly helpful to have some ready-made learning materials. Especially when working with a circuit that's new to you.
Each of the introductory programming activities for CHRP4 includes a set of program analysis activities, as well as a set of programming activity challenges. These are included in comments at the bottom of each of the programs, allowing students to copy and paste code examples from the activities into their program, and modify their program to meet the challenges. Incorporating these activities into the program also simplifies assessment for both the students and the instructor, as students only have to submit one program for marking.
A complete set of programming activities is taking shape, including five introductory programming projects to lead learners through all of the basic coding tasks that will allow them to make their own simple robots, a line-following robot starter project, and two advanced programming activities that allow learners to interface servos (including learning about interrupt code) and SONAR sensors so that they can make their CHRP4 into more advanced object-sensing and Sumo robots.
All of the code is available on the GitHub page.
-
Addressing the challenge of beginner C language coding
04/25/2023 at 18:36 • 0 commentsThe C language is great for beginner computer technology learners to build a better understanding of microcontroller programming and interfacing due to its close connections to the underlying hardware. Unfortunately, the C program syntax and its required supporting structure and functions can also be overwhelming for new learners, and this is why many recent beginner microcontroller boards have made the move to higher-level programming languages like Python, or use block coding.
But, these initially easier solutions come at the expense of the user having full control over the system, and make it more difficult for learners to able to build a full understanding of how the software and hardware work together. This is especially important in a multi-year or multi-semester course that leads from introductory programming and interfacing to students eventually designing, building, testing, and programming their own microcontroller circuits.
I have used a variety of techniques over the years to make it easier for beginners to build their programming skills in C, and these students then find it much easier to move to other programming languages and environments later due to their comprehensive understanding of the structure of typical C programs. Below are some tips that I have had great success with in my classroom.
Treat C expressions as sentences and paragraphs
- get students to understand that much like sentences have nouns, verbs, and end with a period, C expressions typically have nouns, verbs, and end with a semi-colon (because a period would be confused with a decimal point). For example, the C statement 'LED2 = 1;' causes the part (noun) LED2 to become equal to 1, and then the statement is done.
- multi-part statements that work together are grouped together using curly braces (similar to paragraphs). For beginners, who often have a difficult time remembering to close curly-braced structures, I find that vertically aligning the opening and closing braces makes it much easier for them to see which parts of the code work together, or if they have forgotten a closing brace.
Simplify the program code to expose only the main( ) function first
- the programs for the introductory learning activities (think beginner programs, but with coding analysis and exploration activities added – described below) are split into four files. This accomplishes two main goals: simplifying the code so beginner learners are exposed to just the code in the main( ) function first, and making the code more modular and portable (the CHRP4 activities are shared with UBMP4, and the earlier CHRP3 used a different microcontroller, but the main( ) code for all three boards is the same – only the header files and support files are different). See the CHRP4 Introductory Programming Activity 1 - Input and Output program on GitHub to view the four files that make up a project, especially looking at the CHRP4-Intro-1-Input-Ouput.c file containing the main( ) function.
- get students to understand that the main( ) code is split into two parts: one part containing statements that run only once, when the program starts, and a loop containing statements that are repeated by the microcontroller forever. This will help them to envision how the microcontroller seems to respond instantly to a button press for example, while the state of the button is actually being checked many times per second.
Promote guided exploration and real-world/fun activities
- two sections of activities have been added as comments below the main( ) code: Program Analysis Activities designed to help students both understand the program and to carefully scaffold related new concepts onto the program code, and Programming Activities designed to give students practice implementing their own solutions using related programming concepts. Adding these activities to the programs makes it easy for students to copy and paste the examples into their code, answer questions directly in the comments where they remain associated to their code for later reference (and easier grading by the instructor), and allows them to submit one file containing all of their explanations and code modifications for marking.
- the first activity introduces the process of input and output through if structures, the use of the time delay functions in MPLAB, adds exploration of logic gate concepts, and then makes it fun for students to create their own light flashing patterns and beeper sounds, as well as providing them the challenge of implementing a useful real-world equivalent of start/stop buttons.
- quick learners and more advanced students can be challenged with additional related programming tasks to keep them focused while practicing their skills. For this first activity they could be given the tasks of making a short tune using musical note frequencies for example, or exploring code sequencing by trying to make a light show on the LEDs while sounds are playing.
Slowly fold in advanced concepts
- as students progress through the rest of the introductory learning activities they will be introduced to variables, loops, and more advanced programming concepts and functions.
- an especially important feature of CHRP4 for building student understanding is the complete visibility into its function code. The header (.h) and program (.c) files for each activity are easily able to be opened, explored, and modified as the students progress, helping them develop a better understanding of software development as a whole.
Provide code templates for end-of-course challenge projects
- students will be ready for more advanced or end-of-semester challenge projects after having progressed through the introductory learning activities, but beginner learners often find a blank slate approach daunting. They can be eased into the challenges by being provided with a code template and encouraged to work on one small section at a time using the concepts they learned in the introductory activities. For example, a starter template for a Sumo robot program might look like this:
// SUMO robot code template #include "xc.h" // Microchip XC8 compiler include file #include "stdint.h" // Include integer definitions #include "stdbool.h" // Include Boolean (true/false) definitions #include "CHRP4.h" // Include CHRP4 constants and functions // Program constant definitions #define search 0 // Search mode #define push 1 // Push mode // Program variable definitions unsigned char mode = search; // Start in search mode // Motor function (create a motor function here) // SONAR function (create a SONAR function here) int main(void) // Run this code on every startup { OSC_config(); // Set oscillator for 48 MHz operation CHRP4_config(); // Set up I/O ports for on-board CHRP4 devices // Create the code to search for your opponent while(mode == search) { } // Create the code to push your opponent out of the ring while(mode == push) { } }
- in this example, students are able to see an overview of the structure of a simple Sumo robot control program. They can start by writing the code to make their robot's motors move, and then convert their code into a function for use by both the search and push code structures.
- depending on the students' skill levels and the amount of time remaining in the course, an instructor can choose to demonstrate more difficult tasks, such as the creation of a SONAR function, with the class as a whole, develop the function with a group of students, or provide a pre-made function to the class as an example (and an exemplar of good coding and commenting practices) for the students to use
A methodical curriculum combined with a simple robot built using an inexpensive circuit and parts (such as CHRP4 with its simple robot platform) will go a long way to providing new learners with a comprehensive understanding of microcontroller programming and interfacing concepts, and will make it easy for them to progress further using other microcontrollers and programming languages later in their computing careers.
-
Building a simple robot platform
04/23/2023 at 14:12 • 0 commentsFull step-by-step instructions for making a simple and inexpensive robot platform using DC motors and hardware store parts have been posted to the mirobo.tech website.
This platform design specifically targets schools or maker spaces which have tools available to cut the wood for the bases and wheels, as well as a way of cutting the steel axle rods. While a hobbyist can use the design to build one or two robots, it makes more sense to buy the specified materials to build a class set of robots. Ideally, the facility would need to have or have access to: a table saw to cut the platforms to size and to cut the axle slot in them, a rotary tool or metal cut-off saw to cut the hardened steel axles, and a drill press with various sizes of drill bits to drill the mounting holes in the platform and axle holes in the wheels.
The design of this platform is a great choice for beginners building line following robots and simple exploration robots as the drive system includes the ability to slip when the robot encounters an obstacle. Gear motors are a better choice for building Sumo robots, but cost significantly more if the goal is to produce an introductory robot project for youngsters as a school or maker space project. To minimize costs even more, this design can be adapted to use commonly available scrap material for the platforms (instead of buying sheets of MDF) and surplus store DC motors.
-
PCBs and KiCad design files are available!
04/22/2023 at 20:26 • 0 commentsCHRP4 KiCad design files have been posted to GitHub.
Pretty purple as well as beautiful black CHRP4 PCBs are available to order from OSH Park, and boring blue CHRP4 PCBs, PCB + PIC bundles, and complete CHRP4 kits are available at mirobo.tech.
-
Parts list update
04/19/2023 at 02:37 • 0 commentsA parts list for all of the CHRP4 circuit board components has been added to the Hackaday project page, and a public list of parts is also available on Digi-Key which lists all of the Digi-Key part numbers and costs: https://www.digikey.ca/en/mylists/list/SHTZL28E58
While all of the parts are included in both parts lists, certain parts may not be required for specific builds. The Education Starter configuration of CHRP4 is built with a minimal subset of parts to get students programming quickly.
Building CHRP4 into a line-following, obstacle-sensing, or Sumo robot requires nearly all of the components – the primary difference between the two is the line/floor sensors. A line-following robot uses a single IR LED, and two IR phototransistors, while a Sumo robot uses two IR LEDs and two IR phototransistors.
The IR demodulator is optional for all configurations, and allows CHRP4 to be controlled using the UBMP4 circuit or a TV remote control.