Tag Archives: Arduino

Arduino Tutorial 47: Binary and Hexadecimal Bit Flipper

In this lesson we explore how to create a Binary or Hexadecimal Bit Flipper. From our earlier lessons you see we can visually represent Hexadecimal or Binary numbers with a series of LED, with an on LED representing a “1” and an off LED representing a “0”. In programming and circuit applications, it is sometimes useful to “flip” or invert the bits. For an 8 bit number, one could do this in a program with 255 IF statements, but there is a simpler way. If you think about it, you can get the flippedByte by simple subtracting the byte from 0xFF, or 0b11111111. If you try some test cases, you can see that this will always work.

Simply stated, flippedByte=0xFF-Byte,

or if you prefer thinking in binary,

flippedByte=0b11111111-Byte

This is the circuit we are using to drive the 8 LED with the 74HX595 chip, and all this was explained in Tutorial 42.

74HC595
This is the schematic we use in this example to control 8 LEDs from the 74HC595 chip.

This is the code which we developed in the video above.

In all these lessons we are using the Arduino Super Starter Kit, which you can pick up HERE.

Arduino Tutorial 46: HOMEWORK- Create a Binary Bit Flipper with the 74HC595

The purpose of this lesson is to assign you homework. Your homework is to create a Bit Flipper. That is, for an 8 bit Binary or Hex number, invert the bits . . . “1” bits should become “0” and “0” bits should become “1”. For example,

if myByte=00001111

the flipped version of this would be

myByteFlipped=11110000

Similarly if myByte=00000001

myByteFlipped=11111110

You could do this with 255 if statements, but see if you can figure out a better way of doing it, and then demonstrate your results using the circuit we have been using in the last few lessons.

74HC595
This is the schematic we use in this example to control 8 LEDs from the 74HC595 chip.

Arduino Tutorial 44: Understanding Logical Shift Left and Logical Shift Right with the74HC595

In this lesson, we explore how to perform Logical Shift Left (LSL), and Logical Shift Right (LSR) functions on binary numbers, and we implement a circuit to perform these functions using an Arduino and a 74HC595 chip. We will demonstrate these functions on 8 bit binary numbers.

We start with the basic circuit and code which were developed in Lesson 42. In this lesson we are using parts from the Elegoo Arduino kit, which you can get  HERE.  We start with this circuit, which was explained in Lesson 42.

74HC595
This is the schematic we use in this example to control 8 LEDs from the 74HC595 chip.

You can see that with this circuit, an 8 bit binary number can be visually displayed by illuminating the circuit LED. The goal of this lesson is to write code to perform LSL and LSR functions. The graphics below show conceptually how simple these functions are:

logical shift left
This diagram shows the Logical Shift Left function on an 8 bit binary number

MSB stands for “Most Significant Bit” and LSB stands for “Least Significant Bit”.  You can see that the LSL function just moves each bit one to the left, and fills the empty LSB with a “0”.

The LSR funtion is just as simple as illustrated below.

Logical Shift Right
This diagram shows an 8 bit binary number undergoing a Logical Shift Right (LSR) funtion

Such shifts are often required when doing digital logic, so it is important to understand what the terms mean.

We can see that the LSL function can be performed by simply multiplying the binary number by 2. Similarly the LSR function can be performed by dividing the binary number by 2.

Code for LSL:

Code for LSR function:

 

9-Axis IMU LESSON 22: How to Create a Tilt Stabilized Platform with Arduino

In this Lesson we begin to work on developing a tilt stabilized platform using the BNO055 9-axis sensor, and we will take advantage of all the learning that happened in the first 22 lessons. Now though, we will be moving out of the virtual world of Vpython, and will begin working in the real world. In this lesson we focus on getting the gear together. You can go ahead and order your gear, and then next week we will begin assembling and coding. In addition to the arduino nano, and the BNO055, you will need:

You Will Need Two of These HiTEC Servos

NOTE: I am no longer recommending the MG995 four pack of servos, as I have recently gotten several bad batches, so have moved to the HiTEC linked above.

A set of Pan Tilt Brackets:

 PC Board Power Supply (If you have the ELEGOO Kit, you already have this)

Good Wall Wart Power Plug for the Power Supply (if you dont have one)

Bundle of Extra Cables

OK, get your gear ordered and we will start putting things together next week.

Arduino Tutorial 43: Binary Counter with 74HC595 Serial to Parallel Shift Register

In lesson 42 we showed you how to connect and program the 74HC595 shift register. We showed how data in byte format would then be written to an array of 8 LED to give a visual representation of the binary version of that byte variable. We then gave you the assignment to create a Binary Counter using the 4HC595. In this lesson we show you the solution. This builds on Lesson 42, so make sure to have your basic 74HC595 circuit set up before starting this lesson.

In this lesson we are using parts from the Elegoo Arduino kit, which you can get  HERE. 

The code we ended up developing in this lesson is provided below.