Skip to content

A guide on setting up and potentially troubleshooting a Margay data logger

License

Notifications You must be signed in to change notification settings

MNiMORPH/Margay-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Margay-guide

A guide on setting up and potentially troubleshooting a Margay data logger. A more thorough version of this exists here, but my guide is written from the perspective of someone who's new to using Arduino boards and shows some of the issues/questions I had when getting started.

Physical materials needed

I started by gathering all the materials I'd need.

  • Margay data logger (Mine was ATMega 1284p 8 MHz)
    • This is a small data logger that will eventually collect data in the field, but it needs to be set up and programmed before it can do that.
  • Programmer (Mine was the AVR ISP mkll)
    • This is a device that will allow us to burn a bootloader (I'll define this below) onto the Margay board.
  • USB-B cable
    • This is used to connect the programmer to the laptop.
  • USB-C cable
    • This is used to connect the logger to the laptop after initially burning a bootloader, and will keep the logger connected to power. In the field, a battery would supply power.
  • My laptop
    • To download softwares and upload programs to the Margay logger.
Choosing driver in Zadig Margay logger Choosing driver in Zadig Programmer

What is "burning a bootloader"?

This just means that you make your Arduino board capable of receiving computer programs through a USB cable. You do not have to make any physical changes on the board to enable this. All you have to do is connect the board to your computer using the programmer (mentioned in the materials list) and install/configure some software on your computer. Then the board will have this ability from now on, so you won't have to do this more than once.

Most of this guide is about what you need to download on your computer in order to do this, and how you need to configure it.

Software and library downloads

A quick list of downloads I made, before going into more detail on each:

  • Arduino IDE
  • Northern Widget libraries
    • Git Bash (used to install the libraries)
  • SetTimeGUI
    • Processing

I downloaded the Arduino IDE, which will be used to write programs in Arduino and upload them to the logger.

Next, I downloaded the custom Northern Widget libraries found at the link https://github.com/NorthernWidget/NorthernWidget-libraries. There are detailed instructions in the readme, but I'll summarize here. First, I found where my Arduino libraries folder was. The standard location on Windows should be My Documents\Arduino\libraries. You can also find out by going to File > Preferences in the Arduino IDE, and looking at the Sketchbook location towards the top. Your libraries folder should be inside your sketchbook. For me, there was an Arduino folder in My Documents, but it was empty (there was no libraries folder inside). So, I created a "libraries" folder myself.

I downloaded the Northern Widget libraries using git so that updating them would be easier in the future, but had to download Git first (available here). In the Git Bash application, I changed directories into my Arduino libraries folder, then went back to my browser and copied the link from the NorthernWidget-libraries repository. (I clicked on the green Code button at the top of the page, then copied the link under the HTTPS option. More instructions for cloning in git are here.)

Clone link in GitHub

In Git Bash, I entered

git clone https://github.com/NorthernWidget/NorthernWidget-libraries.git

using the link I had just copied. When I checked my Arduino libraries folder again, it now had a folder inside it called NorthernWidget-libraries. However, this folder had multiple subfolders inside, each its own library (for example, the Margay library folder is inside the Northern Widget library folder.) For the Arduino IDE to recognize the individual libraries, take the subfolders out of the NorthernWidget folder, and move them directly into the Arduino libraries folder. You can check whether it worked by hovering over Sketch > Include Library in the IDE, and seeing which libraries you've added.

Note: At the time of writing this, one of the Northern Widget libraries (MCP3421) has the same name as a default Arduino library. Sometimes when I open the IDE, it tells me that updates are automatically available for this library, which really means it's trying to replace the Northern Widget version with the default Arduino version. This will cause issues later. So, don't accept any updates that it tries to push for MCP3421. You can see which libraries it's trying to update by clicking "Install Manually" when you get that notification.

The last thing I downloaded was the SetTimeGUI, with download and running instructions on this page. For now, though, all I did was click the green Code button on that page and used git clone to download the files in the repository (or you could download the zip file.) I needed to download Processing too, in order to eventually run SetTime.

We should now have all the downloads we need, and only need to change some settings before we can start programming.

Board, programmer, and port definitions

All of these changes are made in the Arduino IDE.

Since I was using a Margay data logger (a board compatible with Arduino but considered third-party instead of a standard Arduino board), I needed to configure some settings so that the IDE would recognize the board. A guide for this already exists (with pictures), but I'll still summarize the steps I took.

I went to File > Preferences in the IDE, and a window popped up, with "Additional Boards Manager URLs" towards the bottom. The field to enter text was empty for me at first, but I copy-pasted the following URL into that field and saved changes with OK.

    https://raw.githubusercontent.com/NorthernWidget/Arduino_Boards/master/package_NorthernWidget_index.json

Then, I went to Tools > Board > Boards Manager, and it opened a panel on the side of the screen. I typed in "Northern", and the option for Northern Widget Data Logger AVR Boards came up. I clicked "Install".

Now it was time to select which board I was using. The Margay logger has two versions: ATMega1284p 8MHz (the current version, so it's most likely this one), or ATMega644p 8MHz (older). If you're not sure, this is printed in really small font on the logger (I circled it in red in the picture below.) Mine was the 1284p. I made this selection in the IDE by going to Tools > Board > Northern Widget Data Logger AVR Boards > ATMega1284p 8MHz.

Front of Margay logger

I also had to tell the IDE which programmer I was using. The programmer is only necessary if this is the first time you're using your data logger, since we use the programmer to burn a bootloader (and again, we only have to do this once). The programmer should have a label on it to let you know which one it is - mine was the AVR ISP mkII. I selected this in Tools > Programmer.

Burning the bootloader

Use the USB-B cable to connect your programmer to your computer. Also plug the programmer's ribbon cable into the Margay board, where the 2x3 pin header is. The ribbon should lie across the board rather than bumping against the ridge at the end of the board. However, it can be easy to mix this up, so just try again the other way if burning the bootloader fails.

Then go to Tools > Burn Bootloader in the Arduino IDE, and you should find out within a few seconds whether it worked.

Troubleshooting

If it didn't work, the most common reason is that the programmer's cable is plugged into the board the wrong way. Flip it around and try again.

I was getting an error message relating to the USB port/driver in my laptop where the cable was plugged in. The option for me to select which port I was using in the IDE was grayed out. I downloaded Zadig, which installs a USB driver. Once the Zadig window comes up, use the up/down arrows to select a driver. I chose libusbK.

Choosing driver in Zadig

Back in the Arduino IDE, I now had the option to select a port. Only one option came up for me: COM3, so I selected this, tried to burn a bootloader again, and this time it worked.

Another thing you might want to check is whether the programmer is even turned on.

Uploading programs

To test whether burning the bootloader had worked, I uploaded an example program to the board. I disconnected the programmer, and instead used the USB-C cable to connect the logger to my computer.

”Plugged

A simple example program to test was at File > Examples > 01.Basics > Blink. As its documentation says, it turns the LED on the board on for a second, and off for a second repeatedly. I uploaded this to the logger by going to Sketch > Upload, and saw that the Arduino LED was blinking like expected.

Margay-compatible program

You'll also need to upload a Margay-compatible program to the logger before you can set its clock. A Margay-compatible program is anything with the line #include "Margay.h".

One of these programs can be found by going to File > Examples > Margay_Library > MargayDemo in the Arduino IDE. Compile and upload this to the logger, and the LED may show a series of different colors. You can find out what they mean here.

Troubleshooting

At the time that I compiled MargayDemo (August 2024), there were a few small syntax errors involving capitalization. These will probably be changed by now, but in case there's another program you're trying to compile that hasn't been updated, this is what to do if you get these error messages.

  • "Model_0v0" should be "MODEL_2v2". (You can also go into Margay.h (which you can open with the Notepad app on Windows), and the different options for the model versions are under "enum board".) This error was in line 13 of MargayDemo, which at the time said Margay Logger(Model_0v0);. This is what the error said:

     13:15: error: 'Model_0v0' was not declared in this scope
     Margay Logger(Model_0v0)
     13:15: note: suggested alternative: 'MODEL_0v0'
     Margay Logger(Model_0v0);
                   ^~~~~~~~~
                   MODEL_0v0
    
  • "Logger.Run" should be "Logger.run". This error happened in line 21, which originally read Logger.run(Update, UpdateRate);, and the error message was:

    21:10: error: 'class Margay' has no member named 'Run'; did you mean 'run'?
    Logger.Run(Update, UpdateRate);
          ^~~
          Run
    
  • This last error was the result of me automatically saying yes when Arduino asked me if I wanted to install the available updates for my libraries (it asks this when I open the IDE). I mentioned this in the "Software and library downloads" section, but the Northern Widget libraries include a library called MCP3421, which shares a name with Arduino's built-in MCP3421 library. The NW version has version number 1.0.0, and the Arduino version has number 1.0.4 (at the time of writing this), so it thought I was running an older version of its built-in library. When I accepted the update, it replaced the Northern Widget file with the default Arduino file. This is the error message I got as a result:

     156:3: error: 'MCP3421' does not name a type; did you mean 'CMCP3421'?
     MCP3421 adc;
     ^~~~~~~
     CMCP3421
    

If your error message mentions MCP3421, open the file MCP3421.h inside your libraries location, and read the documentation. If it says Dirk Ohme created it, you have the built-in version (the wrong version), so delete it and re-install the Northern Widget MCP3421 library. The NW version of MCP3421.h should say it was written by Bobby Schulz.

SetTime GUI

We downloaded this earlier, and now we can actually run it to set the time on the logger's clock. While your Margay logger is still plugged into your computer, open Processing (which we also downloaded earlier) and pull up the program NW_Logger_TimeSet.pde. Run this, and a window should appear on your screen with the computer time, logger time, and difference between them. Click the button to set the logger time, and the logger time should now match your computer time. Then you can close the program and unplug your logger. A video with all of these instructions is here.

Coin-cell battery

When setting the clock, insert the coin-cell battery into the logger. This doesn't take the place of battery power, but it's just so that the time you set will stay on the logger.

Preparing for deployment

Assigning a Serial Number

Since the Margay loggers look identical, it can be helpful to have a way to tell them apart, especially if one of them is having issues. Download the program Margay_HardwareTest_v2 and run it in the Arduino IDE. Open the serial monitor (if you're not sure how to do this, see below) and type in "SN Set". It will ask for board type, group number (who is deploying it), and individual ID. Once the serial number is set, it will remain in the board's memory even if you upload a new program to it.

The serial monitor

One way to check if your Margay logger is taking reasonable data before you release it in the field is using the serial monitor. The serial monitor is a form of two-way communication between your computer and the Margay board. Just like uploading programs, it also uses USB to communicate. The serial monitor icon looks like a magnifying glass over a line of dots, and it is in the top right of the IDE, on the teal bar. After opening the serial monitor, you'll have the option to declare the rate of data transmission between your device and the logger, also known as the baud rate. Margay loggers have a baud rate of 38400 bits per second. If you are not sure where to find this, search for Serial.begin() in the Arduino program, and the number inside the parentheses is the baud rate.

If communication is working, you should be able to

The SD card

Insert this into the logger to record data, then insert it into your computer to read the data. You'll use a USB-SD card reader in order to insert it into your computer. Once you have done this, the data will appear on your computer as a text file.

SD card setup The SD card will insert into the silver slot on the logger. The SD card reader is in bottom right and has a slot in the side for the SD card.

After running MargayDemo with the SD card in, the data was saved in this text file.

Battery power

It is powered by 3 AA batteries and needs at least 3.3 V to continue logging. The red and black wires connect to B+ and B-, respectively.

Sensors

BME 280 sensor

This is an external sensor you can attach to read temperature, pressure, and humidity. The wires should be inserted in the same place for both the sensor and the board: the black connects "GND" to "GND", green goes from "SCK" on the sensor to "SCL" on the board, and white from "SDI" to "SDA".

BME 280 setup

Northern Widget has Arduino programs for deployments as well, linked here. I ran the one in the BME280 folder. Now the text file from the SD card has two measurements of temperature, one from the on-board sensor and one from the external one. Here is an example text file of what that looks like.

Connecting to a Monarch

The Monarch logger is a pyronometer measuring incoming radiation in UV, visible, and infrared wavelengths. Its repository can be found here. You can connect a Margay logger to a Monarch sensor to have these additional fields in your data.

You need to upload a program (also known as firmware) to a Monarch logger so it can take data, but you do not need to bootload the Monarch. You can just upload the program right away. Since it can't communicate using USB, you'll use the same programmer that was used earlier in this guide.

In the Arduino IDE, I opened the program v1_B. I needed to select what board I was using, as the Monarch is part of the ATTinyCore group. Just like how I added board definitions for the Margay in the earlier section

, I also needed to add board definitions for the Monarch. I followed these instructions, but basically I just went to File > Preferences in the Arduino IDE and found "Additional boards manager URLs". Since I already had one URL in there, I clicked the button with the two overlapping rectangles, and entered the URL for the Monarch boards on a new line. The URL is: http://drazzy.com/package_drazzy.com_index.json In Tools > Board > Boards Manager, I searched for ATTinyCore and installed the one by Spence Konde. Now, I could select the board and programmer I was using. The board name for the Monarch is ATtiny841 (Micronucleus / Wattuino). I inserted a 6-pin header into the programmer, and held it in place on at an angle so all pins would make contact with the Monarch. Then, I chose Sketch > Upload Using Programmer. Even if it works, lights won't flash on the Monarch, but the IDE will still tell you if it was uploaded successfully.

After that, I went back to the Margay and uploaded a program that would tell it to communicate with the Monarch (I did this using USB cable)

Finally, I wired the Margay and the Monarch together. Green(/brown) goes to SCL, white(/orange) goes to SDA, red goes to 3v3, and black goes to ground.

About

A guide on setting up and potentially troubleshooting a Margay data logger

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published