Going Further
You can use any of the Maxbotix line of ultrasonic sensors to get differing distance characteristics (be sure to change the code to reflect minimum and maximum distance values).
If you're using a Trinket classic with ATtiny85, do conversion from centimeters to inches or other calculations, you should use integer math (best to use an int16_t integer size or larger for big numbers). This avoids linking in the big floating point library for only a few calculations, possibly exceeding the memory available.
For projects using other sensor types, see the tutorials Trinket / Gemma Mini Theramin and Trinket Temperature & Humidity LCD Display.
For errors in the Arduino IDE software with classic Trinket:
- Ensure you have set up the Arduino IDE as listed in the Introducing Trinket tutorial. It is suggested you use the Arduino.cc Arduino IDE version 1.6.7 or greater.
- Ensure you have installed the Adafruit_LiquidCrystal library listed on the first page of this tutorial.The Arduino standard standard LiquidCrystal library does not have the I2C support offered by the Adafruit_LiquidCrystal library.
- Ensure you push the Trinket on board reset button before uploading your sketch, the red LED will blink when ready for upload, there is a 10 second window to do this.
- If you place a large amount of code or other libraries in a sketch, it is very easy to exceed the available code space on the Trinket. If your program absolutely will not fit, consider switching to an Arduino Uno, Adafruit Boarduino, or Adafruit Flora with standard libraries or try to not use a memory hungry library or declare a great number of variables or strings.
- If you get errors similar to the one below, you may have included decimal numbers and the floating point library was added by the Arduino IDE, or otherwise exceeded the amount of program space available.
arduino-1.0.1/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2):relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in /arduino-1.0.1/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_exit.o)
For project issues:
- If you get no display, go to the Hello World I2C sketch and ensure that works.
- If you have no display on Hello World, on the I2C backpack, use the contrast knob to change the LCD display contrast to a readable level. If you decided on an external potentiometer to change contrast and not pin 16 on the backpack, use that.
- If you get no reading of distance, check your wiring from Trinket pin GPIO #1 to the PW pin on the Maxbotix sensor and that the sensor has its 5V and Ground pins connected.
- Ensure you selected Trinket 5V 8 MHz as the Board type in the Arduino IDE Tools menu.
Text editor powered by tinymce.