9 Coding with ChatGPT: Engineering Effective Prompts for Micro:bit Programming

Meagen Giannios

Image created by Meagen Giannios with Microsoft Bing Image Creator.

Prompt: Create a hyper-realistic portrait of an excited young girl working on a robotics project, at a desk, in a artistic futuristic classroom, with other students blurred in the background.

Introduction

Incorporating coding and robotics into the classroom should not be an option. These didactic tools are vital in education because of the profound benefits they have on student learning. Using educational robotics (ER) is an engaging way to improve student motivation and interest in science, technology, engineering, and math. It has been found that when ER have been incorporated into the classroom, there has been a significant reduction in gender stereotypes and an improvement in 21st-century cross-curricular competencies like communication, collaboration, teamwork, creativity, and computational thinking skills (Mury et al., 2022).

In our technology-driven world, it is increasingly vital for young learners to acquire digital and technological skills from an early age. These skills are the foundation of their preparedness for a future where technology plays a central role in almost every industry. BBC Education, Micro:bit Educational Foundation and Nominet created the next gen campaign, donating almost 700,000 micro:bit devices to schools across the UK. This campaign was created in response to research that suggested that 65% of school aged children will have digital careers that do not exist today (BBC Micro:bit, 2023).

 

Image created by Meagen Giannios with Microsoft Bing Image Creator. Prompt: A futuristic image of a young boy and girl proudly working at a computer, with another image depicting their future of being a successful adult fixing a robot. Dream-like, with an emphasis on technology.

With the vast amount of research suggesting that learning about ER, coding, and digital skills is fundamental (Mury et al., 2022), it is clear that there is a significant gap in their integration. This is evident in the findings from BBC education’s research with Nominet. Their research highlights that many teachers struggle with a lack of preparation and confidence when it comes to teaching digital skills. For instance, a staggering 61% of UK primary teachers responsible for computing education lack a background in the subject, with resource limitations posing additional barriers (BBC Micro:bit, 2023). These challenges are not isolated, as Ahmad Khanlari’s study (2016) on teacher participants from Newfoundland and Labrador English Schools District underscores their need for expert teacher assistants and comprehensive support materials like guides and manuals.

There may be a solution. With the use of artificial intelligence (AI) tools such as ChatGPT, teachers with little to no experience with educational technology, may be able to conquer any coding and robotics challenge in the classroom. What is ChatGPT? According to UNESCO (2023), ChatGPT is an AI tool that uses natural language processing to learn from Internet data, providing users with AI-based written answers to questions or prompts. With the use of a chatbot like ChatGPT, students can receive automatic and instantaneous responses to their queries similar to chatting with a course instructor. The research done by Essel et. al., (2022) found that when students interacted with chatbots, this resulted in reduced workload for the instructor and more engaging learning experience for the students.

Image created by Meagen Giannios using Microsoft Bing Image Creator Prompt: A realistic image of a computer with an AI soul, beside a teacher and a student in focus, all working together to solve a problem. The background is a blurred classroom with blurred out students.

Along with using ChatGPT as a learning aid, teachers who are interested in embedding coding and robotics into the classroom should familiarize themselves with SaskCode. Saskcode is a program of the Saskatoon Industry Education Council (SIEC), that provides free robotics and coding training for teachers across Saskatchewan. As well, SaskCode loans grade appropriate robotics kits for K-12 classrooms. One of the robotics kits that spans multiple grade levels and curricula is the Micro:bit GreenTech kit. The BBC micro:bit (Figure 1) is an excellent tool to use when teaching students the fundamentals of coding and electronics. A micro:bit is a small, programmable computer equipped with LED lights, sensors, and various other components. For this presentation, a modified version of the SaskCode micro:bit resource known as ‘Get Your Motor Running‘, will be referred to. This chapter will explore how ChatGPT, when provided with effective prompts, can efficiently program a micro:bit.

Figure 1. The BBC Micro:bit

Note. The front (left image) and back (right image) of the BBC Micro:bit. Own work.

Prompt Engineering

To maximize the utility of ChatGPT, it is crucial to provide context, maintain clarity, and ask concise questions. Here are some tips and tricks to help utilize the potential of ChatGPT effectively:

  • Assign a role to ChatGPT (Cook, 2023). This will make the chatbot adopt the behavior of the role you assign. For example: “I want you to be my coding mentor”, or “You will take the role of being a programming instructor”.
  • Start by providing a clear and concise problem statement. Clearly describe what you want to achieve with your micro:bit program by providing specific details about the code you need.
  • Break down your coding tasks into smaller, manageable steps. This makes it easier for ChatGPT to provide code for specific parts of your project. Test the code often by downloading the code snippets from ChatGPT to your micro:bit.
  • Clearly specify the hardware components that you are using, such as external LEDs, motors, or displays. Include details like pin configurations, and how they are connected to the Micro:bit.
  • Try to understand the code generated by ChatGPT. This will help you troubleshoot issues and make modifications more effectively.
  • Do not forget to exhibit politeness and patience when using ChatGPT.

 

The Process

Step 1. Create a ChatGPT account. 

  • Go to the website: https://chat.openai.com/
  • Click on create an account and enter your email address.
  • Create a password and check your email address for an email from OpenAI. Click on the link to verify your email address.
  • Enter your first name, last name, date of birth and then enter your phone number
  • Enter the verification code that you received by text message.

Step 2. Introduce the coding project.

 

Step 3. Build the micro:bit car.

  • Put together the axel and connect the micro:bit and the battery pack to the motor shield. Add recycled items to create a car chassis. 


Step 4. Construct the micro:bit program.

  • Open two tabs in your internet browser. In the first tab, visit the Microsoft MakeCode for micro:bit website. This code editor is used to program the micro:bit using codeblocks, python, or javascript. In the MakeCode website, click on the purple button “New Project” and name the project “Micro:bit Car”. Once the programming interface opens a new screen, convert code from block-based language to JavaScript by clicking on the language toggle at the top. In the second tab, visit the Open AI ChatGPT website and log in to your account.

  • Next, from the ChatGPT home screen, write the following prompt in the input field:
    Prompt:

    “You are going to be my coding mentor. I need help writing a program in Javascript using the Microsoft Make Code website to program a Micro:bit. The Micro:bit will be connected to a Keyestudio motor shield, and two motors will be wired to A1, A2, B1, B2. The digital write pin14 needs to be turned on in order for the Micro:bit and motor shield to communicate. As well, I want to use specific pins for the motors- digital write pin 12, 13, 15, 16, and analog write pin 1 and 2 to control the speed. Write a program that tells the motors to go forward for 3 seconds, stop 3 seconds, and go backwards for 3 seconds”.

    *Notice that the prompt had specified a role for ChatGPT to play. This can help guide the model’s responses and ensure they align with the desired expertise or perspective. Also included in the prompt were specific details about the components that were being used, and specific directions for the micro:bit.

     

  • When ChatGPT has finished generating the code, copy the code snippets by clicking on the clipboard icon that says ‘copy code’.

 

  • Paste the snippets into the Microsoft MakeCode editor. Click the download button when you are ready. Lastly, disconnect the micro bit from your computer and turn on the battery pack. The motors connected to the micro:bit car should be moving.

 



Step 5. Test and Customize
.

  • Once the micro:bit car has achieved a forward and backward motion, ask ChatGPT to add left and right turns to the program. You can make further customizations such as changing the speed, and adding symbols to the LED display.

 

Affordances and Constraints

There are several potential advantages of using ChatGPT to generate code for students’ micro:bit projects. Some of these advantages include:

  • ChatGPT can generate code snippets rapidly, helping students prototype their projects faster. This can be particularly useful when students want to test different ideas or concepts quickly.
  • ChatGPT can provide explanations and examples that help students understand specific coding concepts, making it a valuable learning aid.
  • ChatGPT can suggest creative coding approaches and ideas that students might not have considered, inspiring them to explore new possibilities for their projects.
  • For beginners, writing code from scratch can be intimidating and frustrating. ChatGPT can help alleviate some of this frustration by providing starting points and guidance, giving them the confidence to experiment and learn without feeling overwhelmed.
  • ChatGPT can introduce students to more advanced coding techniques and libraries that they may not have encountered otherwise.
  • ChatGPT can be a valuable resource for students who have limited access to coding mentors or educators, providing them with instant assistance.

There are also disadvantages to using ChatGPT for coding projects, including:

  • ChatGPT may not fully understand the specific requirements and context of a student’s micro:bit project. A student may have to break their project down into simpler steps.
  • ChatGPT can generate code but it may not be able to provide debugging assistance. Students may struggle if they encounter errors in generated code without knowing how to fix them. Students may need to spend extra time verifying and correcting code.
  • Micro:bit projects can involve physical hardware, and code generated by ChatGPT might not consider the safety precautions. Students will need guidance to ensure their projects are safe and do not harm users or hardware.
  • Lastly, relying solely on generated code from ChatGPT may hinder students’ learning and skill development. Students might miss out on understanding the underlying principles of writing code.


In conclusion, students cannot rely solely on ChatGPT- they will still need to think critically and have some basic knowledge of coding. It is important to have a balance between using AI-generated code and encouraging students to develop their coding skills independently. Over reliance on AI-generated code may hinder deep understanding and creativity in programming. Therefore, educators should use ChatGPT as a supplementary tool in the teaching and learning process, rather than a replacement for hands-on coding experiences.

Critical Media Literacy 

The Recycle Racer project aligns with the Saskatchewan curriculum for grades 5-10, covering a range of subjects such as Practical and Applied Arts (PAA), English Language Arts, Science, and Social Studies. It teaches students electronics and robotics fundamentals, focusing on outcomes including PAA’s Electronics Modules (ELEC02A, ELEC04A) and Robotics Modules (ROBA7, ROBA9, ROBA12A, ROBA13A, ROBA15A, ROBA21, ROBA23A, ROBA28A). In English Language Arts, it fosters group interaction, idea discussion, and independent reading comprehension (CC6.5, CR6.7). In Science, it addresses actions to mitigate human impact on ecosystems (IE7.4) and electricity’s environmental effects (EL6.1). In Social Studies, it encourages local and global community change for sustainability (RW6.2) and evaluates Canadian approaches to environmental stewardship and sustainability (RW8.3). Saskatchewan Curriculum: Saskatchewan Government. (n.d.). Saskatchewan Curriculum. Retrieved October 3, 2023, from https://curriculum.gov.sk.ca/

Recommendations

  1. Perplexity: Perplexity is an AI-based search engine that provides short informative answers to users’ questions. Unlike ChatGPT 3.5, Perplexity also displays the source of the information it provides.
  2.  Microsoft Bing Chat: Microsoft Bing is a search engine developed by Microsoft that provides web search, image search, video search, and has an AI chatbot similar to ChatGPT.
  3. Microsoft Bing Image Creator: Powered by DALL-E, it creates beautiful images based on text prompts.
  4. Google Bard AI: Google Bard is another AI chatbot developed by Google that uses machine learning to generate conversations. Google Bard is unique in the sense that it can generate spoken responses and analyze images and videos to provide more accurate responses. It is not available in Canada as of October, 2023.
  5. Prompt engineering: Learn about a valuable two-step acronym/process used to master the skills of prompt engineering within an academic context.

Informative presentation

Learn more about coding with ChatGPT for micro:bit programming by clicking on the Youtube video above.

References

Ahmad Khanlari (2016). Teachers’ perceptions of the benefits and the challenges of integrating educational robots into primary/elementary curricula. European Journal of Engineering Education, 41(3), 320-330. https://doi.org/10.1080/03043797.2015.1056106

BBC Micro:bit. (2023, May 15). BBC micro:bit – The Next-Gen Groundbreaking Initiative Announced. Microbit.org. https://microbit.org/news/2023-05-15/bbc-microbit-the-next-gen-groundbreaking-initiative-announced/

Cook, J. (2023, June 26). How To Write Effective Prompts For ChatGPT: 7 Essential Steps For Best Results. Forbes.  https://www.forbes.com/sites/jodiecook/2023/06/26/how-to-write-effective-prompts-for-chatgpt-7-essential-steps-for-best-results/?sh=76ea6e6c2a18

ChatGPT by OpenAI: OpenAI. (n.d.). ChatGPT. Retrieved October 3, 2023, from https://chat.openai.com/

Essel, H.B., Vlachopoulos, D., Tachie-Menson, A. et al. (2022). The impact of a virtual teaching assistant (chatbot) on students’ learning in Ghanaian higher education. International Journal of Educational Technology in Higher Education, 19, 57. https://doi.org/10.1186/s41239-022-00362-6

Microsoft MakeCode for micro:bit: Microsoft. (n.d.). Microsoft MakeCode for micro:bit. Retrieved October 3, 2023, from https://makecode.microbit.org/

Mury, S.R., Negrini, L., Assaf, D., & Skweres, M. (2022). How to support teachers to carry out educational robotics activities in school? The case of Roteco, the Swiss robotic teacher community. Frontiers in Education, 7, Article 968675. https://doi.org/10.3389/feduc.2022.968675

Saskatoon Industry Education Council. (2023). SaskCode: Activity 2: Get Your Motor Running! (Green Tech) – Recycle Racer.  https://docs.google.com/document/d/1-7kP5xdqga7bbzxLL3ZAKeCjLxY9r1eI5b5Y6otDxkg/edit

Saskatchewan Curriculum: Saskatchewan Government. (n.d.). Saskatchewan Curriculum. Retrieved October 3, 2023, from https://curriculum.gov.sk.ca/

UNESCO. (2023). ChatGPT and Artificial Intelligence in Higher Education (Authors: Emma Sabzalieva and Arianna Valentini). Retrieved from https://www.iesalc.unesco.org/wp-content/uploads/2023/04/ChatGPT-and-Artificial-Intelligence-in-higher-education-Quick-Start-guide_EN_FINAL.pdf

Wallbank, A. J. (2023, April 28). Prompt engineering as academic skill: a model for effective ChatGPT interactions. Times Higher Education.  https://www.timeshighereducation.com/campus/prompt-engineering-academic-skill-model-effective-chatgpt-interactions

Acknowledgement of AI Use

This presentation was completed with the assistance of various AI tools. The AI tools were used ethically and responsibly during this learning process.

  • Writing: ChatGPT was used to provide feedback on my writing, generate ideas, check for spelling and grammatical errors.
  • Research: Perplexity was used to help find scholarly articles related to the topic presented in this chapter.
  • Presentation: Canva- was used to create the video presentation. Canva is an online graphic design tool with AI-Magic Studio, a built-in library of AI apps.
  • Music: Sound Sculpt Beta– was used to create the music in the video presentation. Sound Sculpt is a free AI music creator.
  • Images: Microsoft Bing Image Creator and Mage.Space, were used to create images. Both of these programs use AI to generate images from text.
  • AI Avatar: IIElevan Labs -AI Voice Generator and D-ID -AI Video Generator, were used to create the AI avatar in the video presentation.

Additional Acknowledgements

I extend my appreciation to SaskCode, a program operated by the Saskatoon Industry Education Council in Saskatoon, Saskatchewan. SaskCode has played an invaluable role in advancing coding and robotics education across the province. Their commitment to providing professional development opportunities for teachers in grades K-12, along with the loaning of grade-appropriate robotics kits, has significantly contributed to the growth of STEM education in Saskatchewan. I am grateful for their permission to utilize the Micro:bit GreenTech Recycle Racer resource in my case study, which has enriched the content of my research. Visit www.saskcode.ca to view PD events and K-12 coding resources. As well, a special thank you to Kara Tooke and Paul Neufeld for reviewing my work and providing professional feedback.

License

Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

AI-Enhanced Instructional Design Copyright © 2023 by Meagen Giannios is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book