miércoles, 19 de febrero de 2020

BLINK

To control the on board LED is pretty simple. The first example you will program is called Blink. To blink an LED means to repeatedly switch between the two possible states by turning it on and off. Like the way processing programs always need to have a setup() and a draw() function, we now need to have a setup() and a loop():

  • setup(): This part of the program runs only once at the beginning. This is where you tell the board what pins you are going to use, and if you are going to use them as inputs or outputs.
  • loop(): This part will run forever (or until you disconnect the power source). The commands in loop() are executed in order, one after another. When reaching the last line, it will start from the beginning again.
Note: Now you're going to start using the IDE, so if you haven't installed it already, go here

Example 2.1


In this example, you will make the on-board LED blink.

Materials

  • 1 x control board

Instructions

  1. Open the IDE and write the following code:
  2. http://verkstad.cc/urler/ctc-g-b2-c-1
  3. Connect the control board to your computer using the USB cable.
  4. Compile and upload the code to the board using this icon in the IDE.

Result

The on-board LED should now blink with a 2 second interval, being turned on for 1 second and then turned off for 1 second.

Commands

  • pinMode (pin Number, INPUT | OUTPUT | INPUT_PULLUP): Used to determine what the digital pin is doing on the board, (OUTPUT) for output (INPUT | INPUT_PULLUP) for signals going into the board.
  • digitalWrite(pinNumber, HIGH/LOW): writes HIGH or LOW to the digital pin pinNumber.
  • delay( time ): Stop the program for a certain amount of time. The time is expressed in milliseconds. If you want to stop the program for 2 seconds, you should write delay (2000).

Remember:

  • Every line ends with a semicolon ;.
  • Blocks of code are contained within curly brackets { }.
  • Functions start with a definition like void.
  • Functions have parameters contained between brackets ( ). The amount of parameters depend on the function.

How it works

  • In setup(), pin 13 is configured as an output. This is the digital pin which the on-board LED is connected to.
  • In loop(), the on-board LED is turned on by writing HIGH to pin 13. This means that you send 5V to digital pin 13.
  • The program pauses for 1000 milliseconds, or 1 second.
  • The on-board LED is turned off by writing LOW to pin 13. This means that you send a "1" to digital pin 13.
  • The program pauses for another 1000 milliseconds.
  • loop() continues to loop.

Add Your Own LEDs


You can add your own LEDs to the circuit. Any electronic circuit you connect needs to be connected to power and ground for the electricity to flow through and power your components. On the control board, power is provided through the IOREF power pin or one of the digital pins (when set to HIGH). The ground pins are marked as GND.

When working with an LED you need to remember that they have polarity. LEDs are constructed to show this. The long leg, named anode, is positive. When wiring it in a circuit, this leg should be connected to power, in this case a digital pin because you want to be able to control it. The short leg, or cathode, is negative and should be connected to GND.



LEDs will not break if you connect them in the opposite way, but they will not work. LEDs cannot carry a lot of current through them. In order to protect them from burning, you need to put a resistor in serial with them. The value of that resistor varies, in the CTC examples a 220 Ohm resistor is always used with an LED. Read more about resistors and Ohm's law here.

To make circuits easier, you will use the Education shield. When mounted on your control board the shield extends the boards capabilities as well as it brings a few extra features. To make a circuit with an LED you will need to use the breadboard on top of the shield. Read more about the breadboard here, and about the Education shield here.


Example 2.2


In this example, you will connect an LED to your control board and make it blink.

Materials

  • 1 x control board
  • 1 x Education Shield
  • 1 x LED
  • 1 x 220 ohm resistor
  • 2 x jumper wire

Instructions



  1. Attach the shield onto the top of the control board.
  2. Connect the LED across the breadboard gap.
  3. Connect a 220 ohm resistor to digital pin 5 using a jumper wire. Connect the resistor to the long leg of the LED.
  4. Connect the short leg of the LED to GND using a jumper wire.
  5. Write the code.
  6. http://verkstad.cc/urler/ctc-g-b2-c-2
  7. Upload the code:

Result

As in the previous example, the LED should blink with a 2 second interval.

How it works

  • In setup(), pin 5 is configured as an output. This is the digital pin which the LED is connected to.
  • In loop(), the LED is turned on by writing HIGH to pin 5.
  • The program pauses for 1000 milliseconds.
  • The LED is turned off by writing LOW to pin 5.
  • The program pauses for another 1000 milliseconds.
  • loop() continues to loop.

Example 2.3


In this example, you will modify example 2.2 slightly. You will keep the same circuit but use a variable to hold the digital pin number where the LED is connected, instead of just writing the number. Check the variable section in the previous Module, if you need help remembering what a variable is.

Instructions

  1. Write the following into the IDE
  2. http://verkstad.cc/urler/ctc-g-b2-c-3
  3. Compile and upload the program:

Result

This example should do exactly the same as the previous one.

How it works

  • The variable ledPin is declared to hold the value 5, the number of the digital pin you are using.
  • In setup(), pin 5 is configured as an output, using the variable ledPin.
  • In loop(), the LED is turned on by writing HIGH to pin 5, using the variable ledPin.
  • The program pauses for 1000 milliseconds.
  • The LED is turned off by writing LOW to pin 5.
  • The program pauses for another 1000 milliseconds.
  • loop() continues to loop.
Note: If you decide to connect the LED to another digital pin, by writing the program this way you only have to replace the pin number at one location in the code instead of three.

Learn by doing


  • Try and see what happens when you change the times inside the delay function. Try making the delays smaller, to see what will happen. Test different ways to make the light blink faster or slower.
  • Use the light to simulate a heartbeat. Check your heartbeat by measuring your pulse. You will notice that you always get two pulses, something like tick tock … pause … tick tock … pause … Try to simulate that with an LED. (HINT: you can copy and paste code)
  • Finally, test to see what happens when the delay becomes really small. Try and notice if you can still see the light blink when you change to delay(10).

VU-meter


It is possible to connect and control more than one LED with your Arduino. When you are using several LEDs in a line, this is called a VU-meter in the CTC program. The EducationShield library contains a class called vuMeter with several functions you can use to easily control several LEDs. Read more about the VU-meter here.

miércoles, 12 de febrero de 2020

INSTALACIÓN DE ARDUINO Y PLACA GENUINO 101

Seguir las siguientes instrucciones paso a paso:

1. Pinchar aquí

2. Descargar Linux 64 bits

3. Pinchar en Just Download

4. Abrir la descarga y hacer doble click en el archivo comprimido arduino-1.8.9-linux64.tar.xz

5. Abrir la carpeta descomprimida

6. Copiar la carpeta arduino-1.8.9 y pegarla en la carpeta Personal

7. Abrir el terminal y teclear cd arduino-1.8.9 y pulsar INTRO

8. Teclear ./install.sh y pulsar INTRO

9. En el Escritorio hacer doble click en el archivo Arduino Desktop

10. Click en Confiar y ejecutar

11. Abrir el IDE

12 Herramientas/Placa/Gestor de tarjetas

13. Escribir Intel Curie

14. Seleccionar Intel Curie Boards e instalar la última versión

15. Esperar hasta que termine de instalarse

16. En el terminal teclear cd .. y pulsar INTRO

17. Copiar y pegar en el terminal lo siguiente y pulsar INTRO:

chmod +x ~/.arduino15/packages/Intel/hardware/arc32/2.0.4/scripts/create_dfu_udev_rule

18. Copiar y pegar en el terminal lo siguiente y pulsar INTRO:

sudo ~/.arduino15/packages/Intel/hardware/arc32/2.0.4/scripts/create_dfu_udev_rule

Pedirá la contraseña. Poner usuario y dar a INTRO

19. Abrir el IDE

20. Ir a Programa/Incluir Librería/Administrar Bilbiotecas

21. Escribir Education

22. Instalar Education Shield

23. Cerrar el IDE y volver a abrirlo

24. Conectar la placa

25. Seleccionar placa Arduino Genuino 101

26. Abrir Ejemplo Basics/Blink

27 Cambiar LED BUILTIN  por 13 en las tres líneas de código y en delay cambiar 1000 por 300, 2000, etc

28. Subir el programa y comprobar