MikroC ARM Project: Interactive Computing with JavaFX and MPU6050 IMU

Interactive Computing

After getting my STM32 microcontroller to read quaterion data from an MPU 6050 IMU, I decided to do a little demo to test how accurate the input is for things such as 3D control. Looking around for a good 3D framework to work with I decided to use the JavaFX 3D graphics framework because it is very easy to work with and Java is a well known language. In this brief post I present to you the methods of using JavaFX with an IMU that takes readings from the user and uses it to manipulate a 3D shape within JavaFX.

Continue reading “MikroC ARM Project: Interactive Computing with JavaFX and MPU6050 IMU”

MikroC ARM Project: MPU6050 IMU with Quaternion Output

MPU6050 IMU

With all this rage about using and programming drones and other robots, the word “IMU” has become to be understood by many persons. An IMU or Inertial Measurement Unit is an important component of robotic systems. The IMU is essentially uses and “fuses” together data from other sensors which is then used to track things such as position, orientation and velocity. In robotic systems and frameworks such as ROS, the data used to measure these things is in the form of quaternion data. Also any device that tracks movement can benefit from using quaternions to determine orientation.

As such a low cost IMU such as the MPU6050 can be used for prototyping and low cost robotics. The MPU6050 is very low cost and readily available from a variety of sources. In this post we look at how we can use the MPU6050 to generate the quaternion data needed for accurate orientation measurement for your robots and devices. Skipping all the complex theory, I will explain what quaternions are and how we can use the MPU6050 to generate quaternion output with the STM32F103C8T6. The principles in this post will apply to any IMU as we only use the MPU 6050 for it’s accelerometer and gyroscope readings and do not use the on board Digital Motion Processing Unit (DMP) calculations.

Continue reading “MikroC ARM Project: MPU6050 IMU with Quaternion Output”

MikroC ARM Project: ISM Band Communication with NRF24L01+

NRF24L01+

When you are looking to add wireless communications to your project, you may be bombarded by a variety of sensors and modules. Your options include WiFi, Bluetooth, LoRa among others. However the NRF24L01+ modules are cheap and readily available and can allow communication wirelessly on the Industrial, Scientific and Medical band (ISM) band. This band is good because its unregulated and if you need to add simple wireless control to your project, it may be viable to use this band to communicate. In this post we look at using the modules with the STM32F103C8T6 ARM microcontroller.

Continue reading “MikroC ARM Project: ISM Band Communication with NRF24L01+”

Choosing a 32-bit Microcontroller: PIC32 vs STM32

PIC32 vs STM32

For years the “Holy War” of microcontroller battles has been PIC and AVR, and whilst the battle in the 8-bit arena is yet to be “officially” decided. I say “officially” because with Microchip acquiring Atmel, I guess we know who the winner is (here’s a hint: it’s Red not Blue).

However, it seems the current trend is toward using 32-bit microcontrollers. Whilst 75% of the tasks we use Microcontrollers for today are handled adequately by 8-bit microcontrollers, it seems “32-bit” has become a buzz word that management likes to throw around. These new Gen-Y and Gen-Z kids also all seem to want to use 32-bit microcontrollers and 8-bit is fast becoming a harder and harder sell. In this post I examine the camps of MIPS vs ARM, PIC32 vs STM32. I will admit to being a PIC fanboy, however I will attempt to be as neutral as possible in my comparison.

Continue reading “Choosing a 32-bit Microcontroller: PIC32 vs STM32”

STM32F030F4P6 Quick-start:- Low Cost, Low Pin Count ARM Microcontroller

STM32F030F4P6

ARM microcontrollers are the future. Despite the claims that 32 bit will surpass 8 bit over the years, we have finally reached the point where for certain projects it may actually be more economical to use 32 bit devices. We have seen a drastic decrease in the price of 32 bit microcontrollers, and the STM32F030F4P6 is one of the cheapest 32 bit microcontrollers today, coming in at under a dollar on Digikey in quantities of 100 or more. This was so revolutionary, I decided to buy 500 of these pieces of silicon and take them out for a spin. Though some 8 bit controllers like PIC or AVR have a lot of Core Independent Peripherals that simplify design, for 80% of what I used microcontrollers for it is not needed. In this quick-start post we explore this tiny and powerful microcontroller.

Continue reading “STM32F030F4P6 Quick-start:- Low Cost, Low Pin Count ARM Microcontroller”

MikroC ARM Project: Interfacing with ST7735 Library

ST7735 

Despite the advent of touchscreens in embedded systems today, sometimes there are applications where an LCD can be used depending on your design. Upon searching for a working LCD module with the STM32F103C8T6 microcontroller and MikroC for ARM, I was unable to find one that was easy to use and understand. So I modified the one that was provided by Adafruit and made it very simple to interface with.

The code can be downloaded from Mikroelektronica LibStock here:

https://libstock.mikroe.com/projects/view/2262/st7735-with-stm32

Enjoy!

 

MikroC ARM Project: STM32F103C8T6 USB HID and pywinusb Python Terminal

USB HID

MikroC is a nice compiler. There are many functions builtin and a lot of microcontrollers are supported from a lot of manufacturers. Therefore I do mot blame Mikroelektronica sometimes when things don’t always work. For example the USB device library they provide does not work with the STM32F103C8T6 microcontroller. So upon searching the forums I was able to find working code from a user called ‘eva’. There was one problem, the code was for USB HID (Human Interface Device) class and communicating with a microcontroller over HID  is not straightforward. I was unable to find an out of the box solution for communicating with a computer over USB. Upon trying many different solutions, I was able write some code to read an HID device with a python library called ‘pywinusb’. In this post I present getting USB HID up and running as well as building a USB terminal to communicate via USB.

Continue reading “MikroC ARM Project: STM32F103C8T6 USB HID and pywinusb Python Terminal”

Starting with 32-bit ARM Microcontrollers Part 6: ADC

Analog to Digital Conversion

In this post we look at Analog to Digital Conversion or ADC. Whether we want to accept it or not our world is an analog one. So at some point when reading data from our world we will need to convert it to a form that our microcontroller can use. That is where ADC comes in. A whole new world of possibilities is opened when we begin to explore Analog to Digital Conversion. Everything from street lamps to ECG machines depend on ADC to function. The STM32F103C8T6 has an ADC module built in and in this post we explore it.

Continue reading “Starting with 32-bit ARM Microcontrollers Part 6: ADC”

Starting with 32-bit ARM Microcontrollers Part 5: UART

UART

Now we reach to using my favorite peripheral. The UART. In case you don’t know what UART is, UART also known as Universal Asynchronous Receiver Transmitter is a serial protocol used for communication in computing devices. Though it may seem like UART is phased out and is no more, it is actually alive and kicking in every modern computer and we will use that to our advantage. In this post we look at using UART with MikroC and talk a little about COM ports.

Continue reading “Starting with 32-bit ARM Microcontrollers Part 5: UART”

Starting with 32-bit ARM Microcontrollers Part 4:- Timers and Interrupts

Timers and Interrupts

Admit it, we are all addicted to throwing that “Delay” function into our programs. Microcontrollers perform many applications that are time based. However when running a bare metal system, there is no OS to schedule what gets done when. So when you throw that “Delay” function in there, your CPU is wasting clock cycles doing nothing. Despite sounding complicated a timer is a very simple peripheral to understand. All a timer does is count. It counts at a frequency that is typically a fraction of it’s system clock. In this post we look at using Timer2 with a STM32F103C8T6. In addition to Timer2 we will also look at using interrupts.

Continue reading “Starting with 32-bit ARM Microcontrollers Part 4:- Timers and Interrupts”

Starting with 32-bit ARM Microcontrollers Part 3:- Input (Read a Pushbutton)

Pushbutton

In the last post we looked at toggling an LED connected to an STM32F103C8T6. We learned that it is very easy to toggle an LED connected to an STM32F103C8T6 microcontroller with MikroC. In fact we were able to blink an LED with 7 lines of code. You want to know something? Reading a pushbutton is just as easy. In this post we look at doing so.

Continue reading “Starting with 32-bit ARM Microcontrollers Part 3:- Input (Read a Pushbutton)”

Starting with 32-bit ARM Microcontrollers Part 2:- Output (Blink an LED)

LED

So we’ve decided to use the STM32F103C8T6 and the MikroC Pro toolchain. Now we go to the next step: output. Usually blinking an LED on an ARM microcontroller is a task. You must configure multiple clocks and ensure that a lot of libraries and files are set up just right. Anyone who has tried to program any ARM microcontroller using the GCC compiler will know it’s not simple. For beginners accustomed to seeing the “setup” and “loop” on an Arduino sketch or is accustomed to using 8-bit micros this may seem like a lot of work to toggle a bit. In this tutorial I will show you how to toggle an bit on an ARM based STM32 microcontroller with less than 7 lines of code!

Continue reading “Starting with 32-bit ARM Microcontrollers Part 2:- Output (Blink an LED)”

Starting with 32-bit ARM Microcontrollers Part 1:- Choosing a Microcontroller

STM32 Microcontroller

 

There are many reasons we would want to use ARM microcontrollers. Microcontrollers with ARM cores are becoming standard for 32 bit embedded systems. While PIC, AVR, STM8 and other microcontrollers are ruling the 8 bit market, the 32 bit market is dominated by ARM. The only other option are MIPS based cores like the PIC32. The reality is that while the PIC32 is fun to use, ARM has the larger share of the market for 32 bit microcontrollers. ST provides a lot of resources for using their microcontrollers. In this post we will look at using the STM32F103C8T6 microcontroller in our designs including: getting started, selecting an IDE and selecting a programmer and debugger.  Continue reading “Starting with 32-bit ARM Microcontrollers Part 1:- Choosing a Microcontroller”