Tag Archive | "programming"

After helping many people get started with the world of Arduino and electronics, we still find a small percentage of people who are turned off by the concept of programming or have trouble breaking larger tasks into smaller ones with regards to writing algorithms for their code/sketch.

So after being introduced to a new graphical programming tool called “Ardublock“, we were excited about the possibilities wanted to share it with our readers. Ardublock provides a truly graphical and non-coding solution to controlling an Arduino, that is an open-source product and thus free to download and try for yourself.

Installation

Ardublock is a Java application that runs from inside the Arduino IDE, which can be downloaded from here. It’s only one file, that needs to be placed in a new folder in the Arduino IDE. The folder names must be the same as shown below:

Once you’ve copied the file, simply open the Arduino IDE and select Ardublock from the Tools menu:

From which point a new window appears – the Ardublock “development environment”:

Using Ardublock

It’s quite simple – you simply select the required function from the menu on the left and drag it into the large area on the right. For a quick example where we blink the onboard LED on and off – watch the following video:

The following image is the screen capture of the program from the video:

As you can see the “blocks” just fit together, and parameters can be changed with the right mouse button. After a few moments experimenting with the Ardublock software you will have the hang of it in no time at all.

And thus you can demonstrate it to other people and show them how easy it is. And there is much more than just digital output controls, all the functions you’re used to including I2C, variables, constants, servos, tone and more are available.

The only technical thing you need to demonstrate is that the Arduino IDE needs to stay open in the background – as once you have finished creating your program, Ardublock creates the required real Arduino sketch back in the IDE and uploads it to the board.

This is also a neat function – the user can then compare their Ardublock program against the actual sketch, and hopefully after a short duration the user will have the confidence to move on with normal coding.

Conclusion

Ardublock provides a very simple method of controlling an Arduino, and makes a great starting point for teaching the coding-averse, very young people or the cognitively-challenged. It’s open source, integrates well with the official IDE and works as described – so give it a go.

And if you enjoyed this review, or want to introduce someone else to the interesting world of Arduino – check out my book (now in a third printing!) “Arduino Workshop” from No Starch Press.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.

Did you know you can use an Atmel ATtiny45 or ATtiny85 microcontroller with Arduino software? Well you do now. The team at the High-Low Tech Group at MIT have published the information and examples on how to do this, and it looked like fun – so the purpose of this article is to document my experience with the ATtiny and Arduino and share the instructions with you in my own words. All credit goes to the interesting people at the MIT HLT Group for their article and of course to Alessandro Saporetti for his work on making all this possible.

Introduction

Before anyone gets too excited – there are a few limitations to doing this…

Limitation one – the ATtiny has “tiny” in the name for a reason:

it’s the one on the left

Therefore we have less I/O pins to play with. Consider the pinout for the ATtiny from the data sheet:

So as you can see we have thee analogue inputs (pins 7, 3 and 2) and two digital outputs with PWM (pins 5 and 6). Pin 4 is GND, and pin 8 is 5V.

Limitation two – memory. The ATtiny45 has 4096 bytes of flash memory available, the -85 has 8192. So you may not be controlling your home-built R2D2 with it.

Limitation three – available Arduino functions. As stated by the HLT article, the following commands are supported:

Limitation four – You need Arduino IDE v1.0.1 or higher, except for v1.0.2. So v1.0.3 and higher is fine.

So please keep these limitations in mind when planning your ATtiny project.

Getting Started

You can use an existing Arduino-compatible board as a programmer with some external wiring. Before wiring it all up – plug in your Arduino board, load the IDE and upload the ArduinoISP sketch which is in the File>Examples menu. Whenever you want to upload a sketch to your ATtiny, you need to upload the ArduinoISP sketch to your Arduino first. Consider this sketch the “bridge” between the IDE and the ATtiny.

Next, build the circuit as shown below:

Depending on the Arduino board you’re using, you may or may not need the 10uF capacitor between Arduino RST and GND. Follow the schematic above each time you want to program the ATtiny.

Software

From a software perspective, to use the ATtinys you need to add some files to your Arduino IDE. First, download this zip file. Then extract the”attiny” folder and copy it to the “hardware” folder which sits under your main Arduino IDE folder, for example:

Now restart the Arduino IDE. As you’re using the Arduino as a programmer, you need select “Arduino as ISP” – which is found in the Tools>Programmermenu. Next – select the board type using the Tools>Board menu. Select the appropriate ATtiny that you’re using – with the 1 MHz internal clock option. Now you can enter and upload your ATtiny sketch. When uploading sketches you may see error messages as shown below:

The message is “normal” in this situation, so nothing to worry about.

Creating Arduino sketches for ATtinys

When creating your sketches, note that the pin number allocations are different for ATtinys in the IDE. Note the following pin number allocations:

digital pin zero is physical pin five (also PWM)

digital pin one is physical pin six (also PWM)

analogue input two is physical pin seven

analogue input three is physical pin two

analogue input four is physical pin three

For a quick demonstration, load the Blink example sketch – File>Examples>1. Basics>Blink. Change the pin number for the digital output from 13 to 0. For example:

Arduino

1

2

3

4

5

6

7

8

9

10

voidsetup()

{

pinMode(0,OUTPUT);

}

voidloop(){

digitalWrite(0,HIGH);// set the LED on

delay(1000);// wait for a second

digitalWrite(0,LOW);// set the LED off

delay(1000);// wait for a second

}

Upload the sketch using the methods described earlier. If you’re using programmer method one, your matching circuit is:

If you’re using programmer method two, this will blink the on-board LED.

Final example

We test the digital outputs with digital and PWM outputs using two LEDs instead of one:

And the sketch:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

voidsetup()

{

pinMode(0,OUTPUT);

pinMode(1,OUTPUT);

}

voidloop()

{

for(inta=0;a<6;a++)

{

digitalWrite(0,HIGH);// set the LED on

digitalWrite(1,LOW);// set the LED off

delay(1000);// wait for a second

digitalWrite(0,LOW);// set the LED off

digitalWrite(1,HIGH);// set the LED on

delay(1000);// wait for a second

}

for(intz=0;z<3;z++)

{

for(inta=0;a<256;a++)

{

analogWrite(0,a);

analogWrite(1,a);

delay(1);

}

for(inta=255;a>=0;--a)

{

analogWrite(0,a);

analogWrite(1,a);

delay(1);

}

}

}

And a quick demonstration video:

So there you have it – another interesting derivative of the Arduino system. Once again, thanks and credit to Alesssandro Saporetti and the MIT HLT Group for their published information. And if you enjoyed this article, or want to introduce someone else to the interesting world of Arduino – check out my book “Arduino Workshop”.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our forum – dedicated to the projects and related items on this website.