Author Archives: SparkFun Electronics

Getting started with the micro:bit – Making a temperature gauge

via SparkFun Electronics Blog Posts

As we continue with the micro:bit series, we look at another onboard feature: the temperature sensor. Interestingly, there is no separate chip for the temperature sensor. Instead, we read from the temperature sensor built into the main processor (nRF51822). While it was originally intended for detecting overheating, we can use it to get an idea of the ambient temperature (just make sure you’re not taxing the processor, as you’ll really start throwing off the readings with the extra heat).

In addition to reading temperatures, the micro:bit is capable of controlling small servos. We can use alligator clips to make connections to the pads or use #4–40 screws to more permanently attach wires. I say “small servos” because the sub-micro servos seem to function with the provided 3–3.3V from the micro:bit. If you need better torque (and actually want to operate the servo in the specified voltage range), you’ll need to find another power source that can provide 4.8–6V.

That being said, the small servos (even at 3V) seem to perform adequately for moving small loads, such as Popsicle sticks and cardboard. In the video, you can see that I glued a Popsicle stick to the servo’s arm and mounted it to a cardboard backing to create a more visually appealing temperature gauge.

Because I love the idea that I can share an interactive version of my code complete with simulator, here is the temperature gauge program from the video:

The micro:bit is still on pre-order, but you can click here to learn more about it.

For anyone who has used servos with students in the classroom, clubs, etc., what kinds of projects have worked well? What materials (e.g., cardboard) do they enjoy using with the servo? Please share your thoughts in the comments below.

comments | comment feed

Friday Product Post: Due Digilence

via SparkFun Electronics Blog Posts

Hello, and welcome to another Friday Product Post! We have a lighter week in preparation for the next couple of weeks, but don’t worry, we have a few things that you are really going to like! This week we are happy to bring you the new Digilent BNC Adapter Board for the Analog Discovery 2 USB oscilloscope, as well as an updated 2xAAA battery holder. Let’s dive on in and take a look.

Run BNC

Digilent BNC Adapter Board

TOL-14260
19.95

The Digilent BNC Adapter Board is a simple add-on board that is intended to be used with the Digilent Analog Discovery 2, allowing you to use standard BNC-terminated test leads and probes with your pocket-sized oscilloscope. The adapter board provides BNC terminations to each of the two oscilloscope channels and enables you to AC couple or DC couple signals to the oscilloscope in the Analog Discovery.

Speaking of the Analog Discovery 2…

Diligent Digilent!

Digilent Analog Discovery 2

TOL-13929
279.95
10

In case you haven’t picked up this pocket-sized USB oscilloscope, we are happy to reintroduce the Digilent Analog Discovery 2. This multifunction instrument allows users to measure, visualize, generate, record and control mixed-signal circuits of all kinds. Developed in conjunction with Analog Devices and supported by Xilinx University Program, the Analog Discovery 2 is powerful enough to replace a stack of lab equipment, providing engineering students, hobbyists and electronics enthusiasts the freedom to work with analog and digital circuits in virtually any environment, in or out of the lab.

Battery Holder - 2xAAA with Cover and Switch

PRT-14219
1.5

This is a simple 2xAAA battery holder that can be adapted to almost any project that can utilize AAA alkaline batteries. This little guy is a revised version of the battery holder we already carried, with the issue of the metal contact resolved.

On top of the products listed in today’s post, we have quite a few smaller “Ding and Dent” items newly available. You can find them on the New Products page or in our “Ding and Dent” category. Be sure to check back in with us next week for even more new products! We’ll see you then.

comments | comment feed

Enginursday: I2Considerations

via SparkFun Electronics Blog Posts

When it comes to microcontrollers, it’s easy to run out of IO pins before you run out of programming space. Back in 1982, NXP Semiconductor (formerly known as Philips Semiconductor) came up with a solution called Inter-Integrated Circuit, or I2C. With this technology, designers are able to connect up to 127 devices using just two pins for clock and data. I2C not only frees up I/O pins but also maintains the measurement from the source to the device reading the measurement. With analog outputs, the output is susceptible to noise, which will need to be filtered through hardware or software. Because I2C is digital, noise can often be ignored, but that doesn’t mean it’s problem free, and there are design considerations that need be addressed — no pun intended.

alt text

One of the first things to look at is the speed to communicate between the microcontroller, known as the master, and the device that is being controlled, known as the slave. For Arduino, the Wire library defaults to 100kHz, but depending on the master and the slave device, you could communicate as low as 10kHz (low-speed mode), to as fast as 3.4MHz (high-speed mode). The faster you communicate, the less amount of capacitance is tolerated on the line, due to the increased rise time of signals. The standard maximum capacitance for I2C lines is around 400pF.

What creates the capacitance, though? There is some capacitance from the devices themselves (around 20pF), but the bulk of the capacitance comes from the wires to connect the devices together. On a circuit board, capacitance isn’t that big of a concern, but there is some created just by having the traces run closely to the ground plane. On cables, however, you could create 40–120pF per meter. For example, with CAT5 cable used for wired internet connections, the capacitance must not exceed 50pF per meter. Shielded cable is higher at 114pF per meter.

What does this mean for the real world? I set up a test using two cables. One was 6 inches long, and the other was 6 feet long. In order to see the effect of cable length more clearly, I removed the pull-up resistors that are normally required for I2C communication.

6 inch cable rise time

6-inch cable

6 foot cable rise time

6-foot cable

With the 6-inch cable, the SDA line (in yellow) sort of looks like a square wave with a rise time of 3.8us. In the 6-foot line, however, the data line looks more like a saw-tooth wave than a square wave with a rise time of around 11us. This is a result of the capacitance of the wires, and grounding the other wire of the twisted pair from the CAT5 cable would increase the rise time even more.

The second half of the design is the pull-up resistors used. I2C uses open-drain technology, meaning that the devices are able to pull the signal down to ground, but are not able to pull the signal high. For that reason, all of our boards that use I2C have pull-up resistors on them. The resistors need to be of a certain value, though. If the resistor value is too high, the rise time of the signals can be too large to be read.

alt text

6-inch cable with a 100 kΩ pull-up resistor

alt text

6-foot cable with a 100 kΩ pull-up resistor

And if the value is too low, oscillations known as ringing can be large enough that the master or slave devices misread the data on the lines. Too small of a resistor value can also prevent the signals from reaching a low enough voltage to be read as a logic 0.

alt text

6-inch cable with 100Ω pull-up resistor

alt text

6-foot cable with 100Ω pull-up resistor

Looking at the waveforms, we can see the ringing when the signals switch from low to high, as well as some crosstalk on the data line when the clock line switches. We can also see that when the signal is low, the voltage is around 1.2V. If our sensor were powered off of 3.3V, that voltage could be too high to be read as a logic 0.

Here at SparkFun, most if not all of our boards use 4.7kΩ pull-up resistors. The value doesn’t need to be too specific, 1kΩ to 10kΩ would work just as well. With 4.7kΩ, though, you can connect a couple devices together without having to disable the pull-ups. But if you’re planning on using a few or more boards on the same I2C bus, make sure you disable the pull-ups on all but one of the boards using a hobby knife.

comments | comment feed

Hardware Hump Day: Earth Day Hacking

via SparkFun Electronics Blog Posts

This Saturday is Earth Day, and all of us at SparkFun are super proud and excited to share how we celebrate Earth Day every day. SparkFun is deeply committed to engaging in environmentally conscious practices and behaviors. From our aggressive recycling habits to our solar panel-covered roof and bike-to-work program, we are doing everything we can to have a minimal carbon footprint.

Today I want to share a simple way to bring the green spirit into your own home with an energy conservation hack. With this project, you will be able to connect any of your appliances to a timer so that they will automatically turn on and off based on your schedule and habits. To make this I used only three parts:

Arduino Uno - R3 SMD

DEV-11224
29.95
19
SparkFun DeadOn RTC Breakout - DS3234

BOB-10160
19.95
12
PowerSwitch Tail II

COM-10747
28.95
7

The below diagram illustrates the circuit.

alt text

Having a hard time seeing the circuit? Click on the wiring diagram for a closer look.

You will notice that there are two open leads going to + and -. These represent the terminals in the PowerSwitch Tail. You will also need to plug one end of the PowerSwitch Tail into the wall and then plug your home appliance into its other end as shown below.

alt text

Once your circuit is completed, it should look like this.

alt text

Now it’s time to upload your program using the Arduino IDE. I relied on the SparkFun DS3234 Arduino Library. This program will turn your appliance on at 7 a.m. and turn it off at 7 p.m. I have added comments in the code for you to follow along and easily customize the timer based on your own schedule.

// Earth Day Conservation Hack by Melissa Felderman for SparkFun Electronics
#include <SPI.h> //include SPI library
#include <SparkFunDS3234RTC.h> //include Sparkfun DS3234 RTC library

//RTC pin definition
#define PRINT_USA_DATE
#define DS13074_CS_PIN 10 

//Power switch tail Pin 
int pin = 7; 


void setup() {

   Serial.begin(9600);

   //start RTC clock
  rtc.begin(DS13074_CS_PIN);
  rtc.autoTime();


  //Pin mode for power switch tail
  pinMode(pin, OUTPUT);


}

void loop() {
//serial print commands for debugging

  static int8_t lastSecond = -1;

   rtc.update();

   if (rtc.second() != lastSecond) // If the second has changed
  {
    printTime(); // Print the new time

    lastSecond = rtc.second(); // Update lastSecond value
  } 

//line of code to control appliance with the RTC. 
//To change the times at which to turn on and off the appliance, change the values in the IF statement. 
  if(rtc.hour() > 7 || rtc.hour > 19 ){
    digitalWrite(pin, HIGH);
  }else {
    digitalWrite(pin, LOW);
  }

}

//function for serial 
void printTime()
{
  Serial.print(String(rtc.hour()) + ":"); // Print hour
  if (rtc.minute() < 10)
    Serial.print('0'); // Print leading '0' for minute
  Serial.print(String(rtc.minute()) + ":"); // Print minute
  if (rtc.second() < 10)
    Serial.print('0'); // Print leading '0' for second
  Serial.print(String(rtc.second())); // Print second

  if (rtc.is12Hour()) // If we're in 12-hour mode
  {
    // Use rtc.pm() to read the AM/PM state of the hour
    if (rtc.pm()) Serial.print(" PM"); // Returns true if PM
    else Serial.print(" AM");
  }

  Serial.print(" | ");

  // Few options for printing the day, pick one:
  Serial.print(rtc.dayStr()); // Print day string
  //Serial.print(rtc.dayC()); // Print day character
  //Serial.print(rtc.day()); // Print day integer (1-7, Sun-Sat)
  Serial.print(" - ");
#ifdef PRINT_USA_DATE
  Serial.print(String(rtc.month()) + "/" +   // Print month
                 String(rtc.date()) + "/");  // Print date
#else
  Serial.print(String(rtc.date()) + "/" +    // (or) print date
                 String(rtc.month()) + "/"); // Print month
#endif
  Serial.println(String(rtc.year()));        // Print year
}

It’s as easy as that! Look at this light automatically turn on for me!

alt text

The best part about this project is the PowerSwitch Tail. With this part, you can easily control any appliances with your sensors and microcontroller. It eliminates the trouble of working with a relay switch and will cut your project build time dramatically!

It’s not pretty, but it’s a quick and easy to way to save energy. If you’re constructing a house from the ground up, you can look into some energy-saving features like the automatic lights and gray outlets at SparkFun’s headquarters. The goal of the outlets is to shut off at night, cutting phantom power draw from any electronics plugged into them. Just like the gray outlets, some of our lights are on a timer as well as motion sensors. One of the really cool features about the lights that are close to the windows is that they have light sensors attached to them. If it is super sunny out, the lights will shut off, and the natural light will flood into the building.

Learn more about SparkFun’s sustainability efforts on Facebook and Twitter (#EarthWeek) and share your Earth Day projects with us there and in the comments below!

comments | comment feed

IoTuesday: Maximize Your WiFi With This One Weird Trick!

via SparkFun Electronics Blog Posts

Terrible clickbait titles aside, I wanted to improve on a project from a few weeks ago. Nick Poole gave me the idea of automating the DIY Yagi-Uda antenna/divining rod I had put together in order to find the orientation of the maximum WiFi signal strength.

The execution was straightforward: mount the antenna and ESP8266 Thing Dev Board onto a pan/tilt bracket with some servos. The ESP8266 code was updated to connect to a WiFi access point (AP) and begin sweeping up and down (about 70°) and left to right (about 180°). At 5° increments, the ESP8266 would take an RSSI reading and remember the yaw and pitch settings of the highest RSSI. After sweeping, the antenna automatically returns to the position with the best RSSI.

Here’s a video of it in action:

There are, of course, a number of problems with this whole setup:

  1. The polarization (roll) of the antenna is not taken into consideration. It would require another servo to test vertical and horizontal orientations.
  2. If the antenna were moved, it would obviously require another maximizer sweep.
  3. If you stand in front of the antenna, place your hand near it, or put any sort of object in its line of sight. You change the multipath propagation of the radio waves, which can mess up the sweep tests or change where the best signal strength might be.
  4. I’m still relying on a poorly made DIY antenna. A professionally made directional antenna should, in theory, perform a lot better than my warped popsicle stick and paperclip monstrosity.
  5. Because the sweep arc is limited, the best connection might be behind the antenna.

Here’s a shot of the rig post-maximization:

WiFi maximizer using a pan/tilt bracket and servos

The OLED display shows an updated RSSI to give you an idea of the connection strength even after the sweep is complete. If you think the given dBm might be unacceptable, then you may want to move the rig and test another spot, especially if you are indoors and multipath is an issue.

If you are interested in trying out the WiFi Auto Maximizer for yourself, you can find the pin connections and code here.

This setup could be useful for performing a very basic characterization of antennas (as per 71784’s suggestion) if you are outdoors and have line of sight to an access point. By sweeping through the different angles, you could develop very simple and limited azimuth and elevation plots. It would not be very accurate, but it could still be useful for those of us without access to an anechoic chamber.

If I wanted to buy an inexpensive 2.4 GHz directional antenna (in lieu of DIY) to test with this rig, what would you recommend? Share your thoughts and suggestions in the comments below.

comments | comment feed

Make a Magic 8 Ball with the micro:bit

via SparkFun Electronics Blog Posts

Last week, I showed you how to boot up the micro:bit and put some simple graphics on the LED array. Today we’ll continue with Microsoft’s MakeCode block editor to make something that approximates a simple Magic 8 Ball.

In case you don’t remember the Magic 8 Ball from your youth, it’s a plastic toy that has a 20-sided die with various messages suspended in blue liquid. You ask it a “yes” or “no” question, shake it and turn it over. A single face of the die appears in a window on the back giving you a random highly accurate prediction of the future.

The micro:bit contains an onboard accelerometer that we can read, and the drag-and-drop editor has several predefined functions for us, including the ability to tell whether the board was shaken. We can use the “on shake” event to generate a random message, like “yes,” “no” and “try again.” If you want to get more creative, you can come up with your own responses (here are the original Magic 8 Ball answers).

One of the neat features of MakeCode is that it can import and decipher special codes stored in the .hex files generated from MakeCode. This means you can share your .hex files with others, and when they import it into MakeCode (Projects > Import File), it recreates the original code.

In addition to sharing the .hex, you can click the Share button to create a web page (hosted on the MakeCode site) where users can simulate the project, download the .hex file and clone your project. In fact, you can embed the shared project on another web page to allow others to play with the code and simulate it (try clicking on the SHAKE button on the micro:bit image below):


Can you think of other projects that might be fun for students to build using the micro:bit and its accelerometer?

comments | comment feed