New capabilities in Blocktinu when writing code in the C programming language

Blocktinu is Tinusaur‘s web-based block programming platform for creating programs to be used with our microcontroller boards or similar based on the ATtiny85 microcontroller by Microchip.

Did you know that Blocktinu can be used to create programs not only by using blocks for absolute beginners but also by writing code in the C programming language?

How does this work?

In the current version of Blocktinu (as of February 2023), in the main menu bar at the top, there is a Projects button that leads to a screen with the two projects we can work on. One is with blocks, and the other is in the C language.

Blockrinu Blocks vs C code

Let’s open the one in C.

Blockrinu Blocks vs C code

There is no code in it initially. This is where block programming can come in handy. So let’s go back to the block project and use the Shield EDUx3IO to make a simple button and LED program.

Blockrinu Blocks vs C code

Now is the time to explain how Bloktinu works.

When we arrange blocks on the screen, the platform actually creates C code for us. Blocktinu also gives us the opportunity to peek into the code that has been generated. This is done with the arrow on the far right of the screen.

Blockrinu Blocks vs C code

We can copy the generated C code from the block project to the C code project and use the Build button the same way to compile and upload the program.

Blockrinu Blocks vs C code

Using libraries

If we want to do something more complex in the C language, for example, reading values from the photoresistor, we will have to use the so-called libraries (or software libraries).

Here again, we can resort to the help of block programming by adding a variable x and assigning it the value of the photoresistor.

Blockrinu Blocks vs C code

We immediately notice that several significant changes have occurred in the C code of the block program.

  1. Added a new line at the beginning of the code:
    #include “tinyavrlib/adcxlib.h”
  2. Created helper function shield_edux3io_photores().
  3. Added new lines in the Initialization section.

This code can also be copied into the C project.

Blockrinu Blocks vs C code

An important question at this point is how do the C language libraries work.

They consist of two files – name_of_the_library.h and name_of_the_library.c, and in this case they are:

  • tinyavrlib/adcxlib.h – the header file that needs to be included.
  • tinyavrlib/adcxlib.c – the source code of the library.

The file “adcxlib.h” contains a description of the library and the functions it implements, while “adcxlib.c” contains the code of those functions themselves.

The ADCxLib library (part of the TinyAVRLib project) helps us work more easily with the so-called analog-digital converters (or ADC) in the ATtiny85 microcontroller.

What Blocktinu does in this case, and which is very convenient for us, is that for the libraries that are installed on the platform, it knows which .h files and which .c files to include in the project.

Another advantage is that we don’t have to install complex and large software packages on our computers in order to program in C. This is because the compilation of our C code is done on Blocktinu‘s servers, where these software packages are already installed.

Blocks or C code?

With Blocktinu, we can create programs with either blocks or in the C language. Which one to choose depends on what we want to achieve, how advanced we are in programming, and how well we know the C programming language.

Solar Charging Pod project kit

Creating programs using a programming language like C provides greater opportunities but also requires much more in-depth knowledge of both the language and the hardware platform.

Blocktinu makes it possible to choose between the two depending on the complexity of the problem we are solving and the task we are solving.

Leave a Comment

Item added to cart.
0 items - $0.00