loading

Visuino has included EEPROM support for quite some time, but I never had a chance to write a tutorial on it. Recently however few people have asked for help on using the EEPROM, so I decided to make one.

In this Tutorial I will show you how easy it is to use the Arduino EEPROM to save values so they can be used the next time the Arduino is powered after being off.

Step 1: Components

  1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
  2. One Rotary Encoder module I got from this cheap 37 sensors set.
  3. 5 Female-Female jumper wires

Step 2: Connect the Rotary Encoder to Arduino

  1. Connect Ground(Black wire), Power(Red wire), Direction(Green wire), Clock(Yellow wire) and Switch (White wire) to the Rotary Encoder Module (Picture 1)
  2. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board (Picture 2)
  3. Connect the other end of the Power wire(Red wire) to the 5V power pin of the Arduino board (Picture 2)
  4. Connect the Clock wire(Yellow wire) to Digital pin 2 of the Arduino board (Picture 3)
  5. Connect the Direction wire(Green wire) to Digital pin 3 of the Arduino board (Picture 3)
  6. Connect the Switch wire(White wire) to Digital pin 4 of the Arduino board (Picture 3)
  7. Picture 4 shows where are the Ground, 5V Power, Digital 2, Digital 3 and Digital 4 pins of the Arduino Nano.

Step 3: Start Visuino, and Select the Arduino Board Type

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/ .

Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select Arduino Nano as shown in Picture 2

Step 4: In Visuino: Add Integer EEPROM Element, and Set the Digital[ 4 ] Pin As Pull Up

To use the EEPROM Module of the Arduino component, we need to add element to it where we will store the value. We can add multiple elements of different types. In our case since we will store Integer data, we will add Integer element. In addition, the button(Switch) of the Rotary Encoder I used does not have built-in pull up resistor, so we will enable the Arduino pull up resistor for Digital Pin 4 where the button is connected:

  1. In the Object Inspector, expand the "Modules" property, then expand the "EEPROM" sub-property, and click on the "..." button next to the value of the "Elements" property (Picture 1)
  2. In the "Elements" editor select “Integer”, and then click on the "+" button to add one Integer Element (Picture 2)
  3. Close the "Elements" dialog
  4. In the Object Inspector, expand the "Digital" property, then expand the "Digital[ 4 ]", then set the value of the "Is Pull Up" property to "True" (Picture 3)

Step 5: In Visuino: Add, Configure and Connect Rotary Encoder Component

To read the data from the Rotary Encoder, we will add and connect a Visuino component:

  1. Type "rotary" in the Filter box of the Component Toolbox then select the "Rotary Encoder Sensor" component (Picture 1), and drop it in the design area
  2. Optionally, in the Object Inspector, set the value of the "Debounce Interval" property to "5" (Picture 2) This will suppress the bouncing noise on some rotary encoders. If your encoder is not noisy, you can leave the value of this property as "0".
  3. Connect the "Out" pin of the Digital[ 2 ] channel of the Arduino component to the "Clock(A)" pin of the RotaryEncoderSensor1 (Picture 3)
  4. Connect the "Out" pin of the Digital[ 3 ] channel of the Arduino component to the "Direction(B)" pin of the RotaryEncoderSensor1 (Picture 4)

Step 6: In Visuino: Add Up/Down Counter Component, and Set Value Element in It

We will add a counter to count the pulses from the rotary encoder. We also need to set a value from the EEPROM into the counter when the power is turned on. For this we will need to add "Set Value" element to the Counter, and add pin to its Value property:

  1. Type "count" in the Filter box of the Component Toolbox then select the "Up/Down Counter" component (Picture 1), and drop it in the design area
  2. Click on the "Tools" button of the UpDownCounter1 component (Picture 2)
  3. In the "Elements" editor select the “Set Value” element, and then click on the "+" button on the left to add a "Set Value" Element (Picture 3)
  4. In the Object Inspector click on the Pin button at front of the "Value" property (Picture 4), and select "Integer SinkPin" (Picture 5)
  5. Close the "Elements" dialog.

Step 7: In Visuino: Connect the Up/Down Counter Component

  1. Connect the "Up" pin of the RotaryEncoderSensor1 component to the "Up" pin of the UpDownCounter1 component (Picture 1)
  2. Connect the "Down" pin of the RotaryEncoderSensor1 component to the "Down" pin of the UpDownCounter1 component (Picture 2)
  3. Connect the "Out" pin of the "Modules.EEPROM.Elements.Integer1" element of the Arduino component to the "Value" input pin of the "Elements.Set Value1" element of the UpDownCounter1 component (Picture 3)
  4. Connect the "Out" pin of the UpDownCounter1 component to the "In" input pin of the "Modules.EEPROM.Elements.Integer1" element of the Arduino component (Picture 4)
  5. Connect the "Out" pin of the UpDownCounter1 component to the "In" input pin of the "Serial[ 0 ]" channel of the Arduino component (Picture 5)

Step 8: In Visuino: Add and Connect Debounce Button, and Inverter Components

We will use the Button(Switch) of the Rotary Encoder (pressing the axle down) to save the current value of the counter into the EEPROM. Since the button has default value of True, and value of False when pressed, we will invert it. The buttons usually have a bouncing noise when pressed or released. I already made Tutorial on how to remove the noise, and here we will use the same Debounce Button component to remove the noise:

  1. Type "button" in the Filter box of the Component Toolbox then select the "Debounce Button" component (Picture 1), and drop it in the design area
  2. Type "invert" in the Filter box of the Component Toolbox then select the "Boolean Inverter (Not)" component (Picture 2), and drop it in the design area
  3. Connect the "Out" pin of the Digital[ 4 ] channel of the Arduino component to the "In" pin of the Button1 component (Picture 3)
  4. Connect the "Out" pin of the Button1 component to the "In" pin of the Inverter1 component (Picture 4)
  5. Connect the "Out" pin of the Inverter1 component to the "Remember" input pin of the "Modules.EEPROM.Elements.Integer1" element of the Arduino component (Picture 5)

Step 9: In Visuino: Add and Connect Start, and Clock Multi Source Components

We want to load the value stored in the EEPROM into the counter as soon as the Arduino code starts executing. For this we can use the "Start" component. It generates a clock event when the Arduino code starts executing. We also want to load the Value of the Set Value element first, and then set that value to the counter. To do this we need the events to happen in specific order. We can use the "Clock Multi Source" to generate multiple events in specified order:

  1. Type "start" in the Filter box of the Component Toolbox then select the "Start" component (Picture 1), and drop it in the design area
  2. Type "clock" in the Filter box of the Component Toolbox then select the "Clock Multi Source" component (Picture 2), and drop it in the design area
  3. Connect the "Out" pin of the Start1 component to the to the "In" input pin of the ClockMultiSource1 component (Picture 3)
  4. Connect the "Pin[ 0 ]" output pin of the ClockMultiSource1 component, to the "Recall" input pin of the "Modules.EEPROM.Elements.Integer1" element of the Arduino component (Picture 4)
  5. Connect the "Pin[ 1 ]" output pin of the ClockMultiSource1 component, to the "in" input pin of the "Elements.Set Value1" element of the UpDownCounter1 component (Picture 5)

Step 10: Generate, Compile, and Upload the Arduino Code

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 11: And Play...

You can see the connected and running project on Picture 1.

On Picture 2 you can see the complete Visuino diagram.

  1. If you open Serial Terminal in the Arduino IDE or Visuino, you will see the initial value of the counter being reset to Zero (Or whatever was stored in the EEPROM before) (Picture 3)
  2. If you rotate the Rotary Encoder, you will see the counter value changing (Picture 4)
  3. If you press the axle of the Rotary Encoder down, the current value of the counter will be saved into the EEPROM
  4. If you power down the Arduino, and then power it up again and connect the with Serial Terminal, you will see that the Counter will be initialized with the value saved in the EEPROM (Picture 5) and in my case will immediately change from 0 to 23 (The value I saved in the EEPROM)
  5. You can continue changing the Counter by rotating the Rotary Encoder (Picture 6)

Congratulations! You have learned how to read and write values into the Arduino's EEPROM with Visuino.

Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com

<p>Hi Boian. As I can put the maximum? does not stop at 23, passes to zero.Accomplish not less than 0 but I can not do ceiling.</p><p>br</p>
Hi Cesar,<br>Not sure what you mean. You can set limit for the counter. It has Min and Max property, and you can set the &quot;Roll Over&quot; there to False, and set Value. In this project I did not use limits, as I just wanted to show how to use the EEPROM, and did not care about other features.<br>Boian
<p>Boian, sorry for my English.</p><p>Various test and end works.</p><p>Thank </p>
<p>Great! Enjoy :-)</p>

About This Instructable

4,805views

56favorites

License:

More by BoianM:Program Arduino UNO With Visuino to Draw on ILI9341 TFT Touchscreen Display Shield With Pen Assemble Kuman Wi-Fi Robot With Camera and Manipulator Arduino and Visuino: Long Distance Remote Light Sensor With RFM95W/RFM98W Makerfabs LoRa Shields  
Add instructable to: