I don't know why I blog, because? I have no agenda, just love electronics and want to share. I love to follow other experimenters/hardware hackers just to see what other people are working on. Shoot me a message if you blog.
As I start my design of an SRS Robo-Magellan robot I have the strong desire to build off my successes and failures and of course; try something different.
On my list of “wants” is a sensor to measure distance to ground. Obviously this is normally fix unless you have suspension, and indeed I have suspension. I want to ensure my robot doesn’t bottom out while climbing hills, or if I’ve come upon a bit of a gap I don’t want my wheels to roll over.
My perception of the issue is .. grass.
Problem: I want a sensor that can give me AGL that see’s mostly into the grass. I would love if it if was non-contact but still has to be mostly water proof.
First up is one pile of junk, but good enough for the basics. An ultrasonic sensor the HC-SR04
Measured Frequency ~38KHZ
250mm accuracy <5mm
I presented sample container to sensor. The container was about 120mm wide with grass. I found surrounding area affected readings so I hacked together a cone for the sensor. The cone corrected the reading abnormalities.
Sample weed-like grass had a rough dirt floor at 70mm above base table. The sensor is 255 millimeters above the table base.
Measurement of 10 reading rolling average was 117-122mm from table base to measured height.
Unfortunately this doesn’t really get us as far into the grass as I’d like. Worst thought is that the tallest blades rose to within 5mm from cone visibility and started causing sensor reliability issues, giving me readings greater than the length through the base. This sensor, in my opinion, is unreliable for this application.
… parts ordered for future testing but suggestions welcomed.
I’m now working on my eighth version of my Pop-Can Challenge Robot. As I have re-imagined my robots I continue to grow and learn better ways to accomplish things. I’ve also purposely made changes just to keep myself trying different things.
My first robot was made my comfortable choice of PIC Microcontroller(s) v0.1 was one, v0.2 was three. To laser cut design pieces, eventually adding 3D printing pieces from thing-a-verse to now using CAD to design my robot before building-on-the-fly. I’m adjusting some life priorities because I know I spread my hobbies a bit thin… and I’m not getting the time I need to finish this robot… there is a certain point where something takes more hours than you might have to offer, and I just can’t get over the ledge on software without a deeper commitment. I also hope to build a Robo-Magellan bot as well.
I will try to curate my design thoughts, considerations, and goals to break down how I built this robot and why it’s what it is… I’ve failed dozens of times, made massive painful changes, learned a ton from friends and those failures… and hope that I can provide the next person with a little inspiration; be it to improve on what I did, prove I could have done something better, or whatever the motivation. If you want any part of the design down to the code of my work let me know… I’m terrible about documenting, but I am hopeful to change that going forward. My goals going forward are to better document what I am working on so that you can easily copy and speed up the time for developing your own project. I also encourage you to share your project(s), including failures to help the wider community.
I purchased a 2-pack of rip off NES 8bit controllers on Amazon with an “extension” cord so that I had a ready made connector. Cut the extension cord off and wired it to an Arduino Mega (because that’s what was on the bench). I am using this for a game I am working on for the Makerspace… but through maybe you could use a snippet that worked. The first google code I tried to copy and paste didn’t work so hot.. so here is what I came up… I did find some inspiration here and there but this is a good launching point for your next project.
/*
NES Controller
*/
const int latch = 50;
const int clock = 48;
const int data = 49;
#define latchlow digitalWrite(latch, LOW)
#define latchhigh digitalWrite(latch, HIGH)
#define clocklow digitalWrite(clock, LOW)
#define clockhigh digitalWrite(clock, HIGH)
#define dataread digitalRead(data)
#define wait delayMicroseconds(15)
unsigned long previousMillis = 0;
const int wait_interval = 20;
const int A_BUTTON = 0;
const int B_BUTTON = 1;
const int SELECT_BUTTON = 2;
const int START_BUTTON = 3;
const int UP_BUTTON = 4;
const int DOWN_BUTTON = 5;
const int LEFT_BUTTON = 6;
const int RIGHT_BUTTON = 7;
byte output;
void setup() {
Serial.begin(115200);
pinMode(latch, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(data, INPUT);
Serial.println("NES TEST");
}
boolean isBitSet (byte myVar, byte bitNumber) {
bool bitvalue;
bitvalue = myVar & (1 << bitNumber);
return bitvalue;
}
void readNES() {
latchlow;
clocklow;
latchhigh;
wait;
latchlow;
for (int i = 0; i < 8; i++) {
output += dataread * (1 << i);
clockhigh;
wait;
clocklow;
wait;
}
}
void hexprint(byte b) {
Serial.print("0x");
if (b < 10) Serial.print("0");
Serial.println(b, HEX);
}
void loop() {
output = 0;
readNES();
if (!isBitSet(output, 0)) Serial.println("A Button");
if (!isBitSet(output, 1)) Serial.println("B Button");
if (!isBitSet(output, 2)) Serial.println("SELECT Button");
if (!isBitSet(output, 3)) Serial.println("START Button");
if (!isBitSet(output, 4)) Serial.println("UP Button");
if (!isBitSet(output, 5)) Serial.println("DOWN Button");
if (!isBitSet(output, 6)) Serial.println("LEFT Button");
if (!isBitSet(output, 7)) Serial.println("RIGHT Button");
//Serial.print("Read: "); hexprint(output);
}
I thought I’d drop this here for someone who needed a copy-paste solution.
I am parsing a serial string output from a YDLIDAR X4 rotating lidar. I have to do this because the library sucks. a lot. I mean I’m not over my heels with the unit anyhow, first off who the hell outputs at 128,000 baud? I’ll post the code when it’s done enough for someone to build off of it.
I was getting an error in number of bytes in the packet as parsed from the serial string so I had to break out the function into really busy but obvious code to see where I was going wrong. The code has me concatenating two bytes and an upper nibble. Ignore the discrepancy in how I added my bytes backwards in my code vs. how the device actually stacks it’s data… because you know: WHO IN THEIR RIGHT MIND SHIFTS LSB ON THE LEFT?! (note the “length bytes as shown in 12 bits and the “response length” example below.)
Anyhow… feel free to show me how to do it better in the comments. Obviously this is built for you to look at it do it’s magic in a serial monitor.
What a groaner.. who needs another datalogger? Well I do, so stuff it. I was inspired to check out these iButtonLink devices that allow you to daisy-chain connect a number of devices in a single circuit of sorts with RJ45 patch cables. I had seen these a couple years ago in some top-notch datacenters that terminated to a concentrator (4 strings) that were then pushed up to some IBM services app server.
A while back I published a Microsoft PIC microcontroller version of this … I decided to give it another whirl with the “easy button” … Arduino. Of course there were a couple libraries that I just had to collectively stuff into the same sketch and easy-peasy it was done in an hour or so.
This time I have my data stored to an SD card, which … I hastily put together.
If I was actually going to finish this I would add three things to this to finish it up.
Use an RTC, figure an interface to enter the correct time. (maybe add an ethernet shield and get NTP?) … or just manual enter.
I’d grab the interval time off the RTC and just have the loop do a non-blocking wait, then poll the RTC time or interrupt (whatever you favorite way to do this is..) that way I was collecting trend information on the “:00″s.
I would add a method of checking for an SD card to be interested and allow it to start logging from card insert. I would also add time/date stamp to the file and finally, still SD card related I would check file size and stop logging when I got close to full.
So that is that. I’ve been creating a lot of fun lately but nothing mind-bending.. just going through every module I’ve ever bought doing the demo code … or going the other way around.. working on every Arduino demo/example in a class .. I’ve also built an FE boat, moved my workshop inside (update video coming kind of soon) and been working on PopBot 0.5 ..
The code:
/*
* Chas Ihler
* @chasxmd
* https://iradan.com
*
* License: Public Domain - it's mostly copy and paste and preferences anyways.
*
* iButtonLink, grabs all sensors and logs them to card if present.
* Recommendations:
* Add an RTC and a method of updating time.
* I'd also grab actual seconds off the RTC for logging and use a non-blocking wait for the polling/logging.
*
* Libraries:
* https://github.com/matmunk/DS18B20
* IDE built in SD card/SPI library
*
* Sensor:
* https://www.ibuttonlink.com/products/t-sense-temperature-sensor
* which has this device within..
* https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
*
* Hookup:
* You'll need a pullup resistor from 5V to pin 2
* ibutton hookup:
* 1 - GND
* 2 - 5VDC
* 3 - NC
* 4 - Arduino Pin 2 (w/ Pullup)
* 5 - GND
* 6 - NC
* 7 - NC
* 8 - NC
*
* SD card attached to SPI bus as follows:
* MOSI - pin 11
* MISO - pin 12
* CLK - pin 13
* CS - pin 4
*
*/
#include <DS18B20.h>
#include <SPI.h>
#include <SD.h>
DS18B20 ds(2); //pin 2
const int chipSelect = 4;
void setup() {
Serial.begin(115200);
delay(100);
Serial.println("----------------------------------------");
Serial.println(" ");
Serial.println("DS18B20 / iButtonLink Demo");
Serial.print("Devices: ");
Serial.println(ds.getNumberOfDevices());
Serial.println(" ");
Serial.println("----------------------------------------");
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
}
void loop() {
int i_address;
Serial.println("----------------------------------------");
while (ds.selectNext()) {
String str_dataString = "";
switch (ds.getFamilyCode()) {
case MODEL_DS18S20:
Serial.println("Model: DS18S20/DS1820");
break;
case MODEL_DS1822:
Serial.println("Model: DS1822");
break;
case MODEL_DS18B20:
Serial.println("Model: DS18B20");
break;
default:
Serial.println("Unrecognized Device");
break;
}
uint8_t address[8];
ds.getAddress(address);
Serial.print("Address:");
for (uint8_t i = 0; i < 8; i++) {
Serial.print(" ");
Serial.print(address[i]);
str_dataString += String(address[i]);
}
Serial.println();
/*
Serial.print("Resolution: ");
Serial.println(ds.getResolution());
Serial.print("Power Mode: ");
if (ds.getPowerMode()) {
Serial.println("External");
} else {
Serial.println("Parasite");
}
*/
Serial.print("Temperature: ");
Serial.print(ds.getTempC());
Serial.print(" C / ");
Serial.print(ds.getTempF());
Serial.println(" F");
str_dataString += ",";
str_dataString += String(ds.getTempC());
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(str_dataString);
dataFile.close();
Serial.println(str_dataString);
} else {
Serial.println("error opening datalog.txt");
}
Serial.println(" ***** ");
Serial.println();
}
delay(30000);
}
Using a PIC Microcontroller to pull temperature of iButtonLink T-sense sensor.
I pulled this off the wayback machine because I lost this post in the great database loss of how ever many years ago. I’m re-posting because I’m working on an expanded version of this with an Arduino dev board and wanted a reminder of what I did five years ago. Originally posted 1/2/2015. No edits.
—————————————————————————————————————-
I came across a stash of iButton T-sense 1-wire sensors.. so I grabbed a couple and decided to check out 1-wire.
Maxim makes a 1-wire device called the DS18B20. It’s a 9-12 bit temperature sensor with the possibility of being powered by parasitic power from the data line. This cuts the signal path down to a single DQ line and a return. A company called iButtonLink produces a nice little wrapper around this device called a T-Sense. There are a couple pieces of software out there that will allow you to hook these up to monitoring systems, I don’t have any though. These devices come with a 64-bit address code and can be daisy-chained which makes having many of these devices monitored very nice.
At first I thought, ugh.. lame I have to send, and parse 64-bit codes in a little 8 bit micro.. doesn’t sound like a ton of fun for just fooling around on a day off.. thank fully they have a “Skip ROM” feature/command which works similar to a broadcast but can only be used when you have one device on the bus. If there is one thing left in this project I might consider finishing it’d be to add the addressing in and daisy-chain a few of these.
For my circuit I hooked up 5VDC (but later ran it on 3.3V just fine) and the 5VDC return on pins 1 & 2. Then the DQ link and return on pins 4&5. The signaling is interesting as the 1-wire bus needs a weak pull and works with an open collector circuits. The master starts all signaling, writes and reads. The 1’s and 0’s are based on how long the master or slave sinks the DQ line. To accomplish this in the PIC microcontroller I switched the port from an output to a three state input when I needed the port to be in weak-pull up mode (which is also hand when I need to sample the port for a response from a slave). The pull up on the resistor in my circuit is 10Kohm but I’ve seen 4.7KOhm and I’m sure anywhere in the neighborhood is fine. Finally if you do some digging you’ll notice I run this in low speed mode, if I remember correctly the “high speed” mode is 4x faster. I don’t think speed of data transfer is really relevant when you’re waiting for 750ms for a temperature conversation though.
I initially started with just determining if there was a 1-wire device on the bus. If you perform a “reset” (master sinks the bus low for 480us then releases to hi-z for 70us and then performed a sample.. any (all) device(s) will sink the line slow to prove their presence…then another 410us of delay before continuing. I got this one first try.. better luck than my first time with I2C! I then wrote the code (including sampling tidbits of Microchip AN1199 code to optimize) to do an actual temperature conversion and request it (by commanding a “read scratch pad”). The device dumps all 9 bytes of it’s registers. On that note I just remembered I should mention I did NOTHING with the CRC byte.. that’s all you if you care.
My temperature conversion code looks like this: (bus control m = master or PIC, s=slave or sensor)
m RESET
s PRESENCE flag
m SKIP ROM (0xCC)
m CONV TEMP (0x44)
m HOLD DQ (Hold line high 750ms for 12bit conversion .. I am guessing we hold it high for the parasitic power supply)
m RESET
s PRESENCE flag
m SKIP ROM (0xCC)
m READ SCRATCHPAD (0xBE)
s 9 Bytes of Data
The 12-bit conversion is basically 0.0625 deg C for every bit from 0C, The LSB holds a temperature sign.
The output of my program looks like..
There are tons of details on what a “1” is an what a “0” is, the ROM code (READ ROM, MATCH ROM), changing the configuration to 9bit for 94 ms conversions over 12bit 750ms conversions. This is all stuff you can grab out of the DS18B20 specification sheet or AN1199.
I hope you get some use out of this.. I still have enough of these T-Sense modules.. maybe if someone really wants one I’ll drop it in the mail… or perhaps we can set up a big box of electronics to ship around and I can dump some in there.