ATtiny85 I2C SSD1306 screen not working - arduino

I have been on this issue for more than 3 days now after I got my SSD1306 I2C in the mail. I have a Tiny Programmer from Sparkfun, which I use with a breadboard.
This is my pin layout: pin2-->SDA, pin3-->SCL. The documentation on the SSD1306 Arduino library states that I have to use these pins even though I know the SDA is pin5 and SCL is pin7. The power and ground are being jumped to the OLED from the Tiny Programmer.
The main issue I am having is that the OLED is not coming on or displaying the text.
The code I am using for this is:
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
void setup() {
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
ssd1306_128x64_i2c_init();
ssd1306_fillScreen(0x00);
ssd1306_charF6x8(0, 0, "Line 1. text");
ssd1306_charF6x8(0, 1, "Line 2. Bold text", STYLE_BOLD);
ssd1306_charF6x8(0, 2, "Line 3. Italic text", STYLE_ITALIC);
ssd1306_charF12x16(0, 3, "Line 4. Double size", STYLE_BOLD);
}
void loop() {
}
There is no error message when I compile this and I honestly have no idea what's going on.
I have tried swapping the SDA and SCL and still nothing. I have even used the actual SDA and SCL pins and still nothing. I feel that I am out of options and/or the OLED is broken. I'm just seeing if there is anything else I can do before I try to get a replacement for this? Thank you.

I think you have to use pins 5 and 7 with the attiny85. You also need to use tinywirem.h for I2C communication.

The ATTiny85 I2C pins are pin5(PB0) SDA and pin7(PB2) SCL, the SSD1306 library seems to think they are pin3(PB4) SDA and pin2(PB3) SCL, the demos even have an diagram of an ATTtiny within them showing the incorrect pins. I have used the official pins with no luck. Using the pins they suggest did actually run but just so slowly most would think it was not working. It took minutes to start clearing the screen, and even longer to actually clear it.
I have used the U8g2 library instead, the init entry for the Digispark ATTiny85 works OK for the u8x8 helloworld demo though I could not get many of the demos to compile for the ATTiny85. I am still looking for a better solution.

Related

How to read the reset vector on an ATMEGA328

I have several ATMEGA328 based custom boards: I recently found that the standard Arduino bootloader does not handle watchdog timeouts correctly (it keeps resetting, so the device is effectively bricked until the next power cycle) so I am switching to the Optiboot bootloader.
I want to add something to my app that tells me whether the bootloader is Arduino or Optiboot. As Optiboot is a lot smaller, the reset vector is different, so printing that out would be a good indication.
Serial.println (pgm_read_word_near(0), HEX);
The above line of code prints out 940C, and I was expecting something like 7E00. How can I print out the address from the reset vector?
The actual address of the start of the boot flash section is determined by the BOOTSZ fuses.
This reads the size of the bootloader for classic ATmega:
uint32_t bootloaderSize;
cli();
uint8_t highBits = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
sei();
if (!(highBits & bit(FUSE_BOOTRST))) {
uint8_t v = (highBits & ((~FUSE_BOOTSZ1 ) + (~FUSE_BOOTSZ0 )));
bootloaderSize = MIN_BOOTSZ << ((v >> 1) ^ 3);
}
use #include <avr/boot.h>

ESP8266 "ovf" when doing small double maths

I'm using a Wemos D1 based on the ESP8266 wifi chip with the Arduino C framework to do some simple small math.
As far as I can gather, double precision is available so I'm using it - with a maximum of something like 1.8*10^103.
But I'm getting an ovf when I try to calculate a number around 5*10^8.
Any ideas please?
void setup(){
Serial.begin(9600);
while(!Serial);
Serial.println("Hit any key to start math");
double te = 6800;
double res = te * te;
Serial.println(res);
te = 68000;
res = te * te;
Serial.println(res);
te = 680000;
res = te * te;
Serial.println(res);
}
void loop(){
}
Prints
46240000.00
ovf
ovf
Arduino does supports 4-byte double data type. and your code is indeed produced a valid double value that is not overflow (ovf).
The problem that you see has to do with the way Arduino implement Serial.print() function which is almost like a half-cooked hack to support floating-point and is not as reliable as vprintf() that is available in avr-libc. You can see the source code here which print ovf for anything bigger than 4294967040.0 or smaller than -4294967040.0. I thought that ESP8266 Arduino Core has fixed this instead of inheriting the ugly implementation of Arduino Serial.print(), but apparently not.
Luckily the ESP8266 Arduino Core does have a Serial.printf() method that provide better floating point rendering. This code will shows that your number is indeed a valid number for double data type.
void setup(){
Serial.begin(9600);
while(!Serial);
double te = 68000;
double res = te * te;
Serial.println(res); //this will produce 'ovf'
Serial.printf("Result=%f\n", res); //this will produce correct 4624000000.000000
}
Please noted that Serial.printf() is ESP8266 specific implementation to support full floating point vprintf() in the standard library. It is not available for standard Arduino Boards.
For Arduino boards, there is a way to use sprintf() which inherits from vprintf() to print the correct floating point with some twist on linker options during code compilation process. I have a blog post Do you know Arduino - sprintf() and floating point talk about how to do that.

How do I rotate 2 steppers at the same time?

Is there somethimg like theading in arduino?
I'm using Stepper.h library to use steppers and I want to rotate two of them at the same time, is that possible?
Additional info:
I'm using two drivers ULN2003 and Arduino Nano to controll steppers.
Code for one of them:
void AStep(){
AStepper.step(i1.toInt());
display.println("Turned A stepper;");
display.display();
}
You can make them appeir as they are moving at the some time by making the stepper do smaller "steps".
The only thing is that this method DOESN'T make them turn in actual sync.
Snippet by PaulS from the Arduino forums.
for(int s=0; s<step_360; s++)
{
AStepper.step(1);
BStepper.step(1);
}

DC motor speed is too low while interfacing with L293D morot Driver and Atmega8

I am trying to drive a 6v dc motor with L293D driver and Atmega8 without PWM. The problem is i am getting very low speed while connecting the motor with L293D driver. But, it rotates well when i provide direct 6V dc supply to the motor. I am using external 6v source at V2(motor supply) pin of L293D, but no improvement. The motor does not rotate until i turn the rotor with hand. Is the problem remaining for not using PWM? My code is here:
DDRB = 0xFF;
while(1)
{
PORTB = 0B00000010;
_delay_ms(20000);
}
i think may be you forgot to make Enable 1 pin high, if your connections is like this than
PB0 --> IN1
Penter code hereenter code here`B1 --> IN2
PB3 --> EN1
and pin 8 of L293d will connected with External Battery.
than code like this :
DDRB = 0xFF;
while(1) {
PORTB = 0B00000110;
_delay_ms(20000);
}

Arduino's analogRead() returns junk when I print via serial

I'm making a clock with the Arduino, and I want to make a button to set the time.
So, just to test, I pluged a wire in the Analog Input pin 0 and wrote two lines of code to read the pin and print it via Serial, but all I get is junk.
valm = analogRead(0);
Serial.println(valm);
And what I get from the serial monitor is this:
?j?d?±µ?Ê??jDd?±µ???ºjRd?±µ???ºj?d?±µ?Ê??j?d?±µ?É?ªjRd?±µ???ÊjRd?±µ???Âj?d?±µ????j?d?±µ?É??j
Rd?±µ????j?d?±µ???ºj?d?±µ?É??jRd?±µ????j?d?±µ?Ê?ÊjDd?±µ???Âj?d?±µ????j?d?±µ?É??jRd?±µ????j?d
?±µ?É?ÂjRd?±µ???Êj?d?±µ???ªj?d?±µ?Ê?Êj$d?±µ???ÂjRd?±µ????j?d?±µ????jdd?±µ????jRd?±µ???Âj?d?±
µ?É?ÊjRd?±µ????j?d?±µ?Ò?Êj?d?±µ?É?ÂjRd?±µ????j?d?±µ????j?d?±µ?É??jRd?±µ???Âj?d?±µ???Êj?d?±µ?
??ªj?d?±µ???Êj?d?±µ???ÂjRd?±µ????j?d?±µ????j?d?±µ?É??jRd?±µ???Âj?d?±µ?Ò?Êj?d?±µ?É?ªj?d?±µ?É?
?jTd?±µ???Âj?d?±µ????j?d?±µ?É??jRd?±µ????j?d?±µ?É?ÂjRd?±µ???Êj?d?±µ?É?ªjRd?±µ???Êj?d?±µ???ºj
?d?±µ?È??jTd?±µ????jRd?±µ???ªj?d?±µ?È?ÂjTd?±µ?É?ÊjRd?±µ???ªj?d?±µ???Êj?d?±µ???ºj?d?±µ?É??jRd
?±µ???Êj?d?±µ???ªj?d?±µ?É?ÂjPd?±µ???Êj?d?±µ???ªj?d?±µ?Â?Êj?d?±µ?É?ºjRd?±µ????j?d?±µ?É??jRd?±
µ???ªj?d?±µ?Ê?Âj?d?±µ???ÊjRd?±µ???ªj?d?±µ?Ò?Êj?d?±µ???ºjRd?±µ????j?d?±µ???Êj?d?±µ?Ê?ªjdd?±µ?
??ÂjRd?±µ???Âj?d?±µ?É?ªjPd?±µ???Êj?d?±µ????j?d?±µ?É??jRd?±µ???Êj?d?±µ?É?ªjdd?±µ???ÂjRd?±µ???
Âj?d?±µ?É?ªjDd?±µ???Êj?d?±µ?Ê??j?d?±µ?É??jRd?±µ???ÊjRd?±µ???ªj?d?±µ?Ê?ÂjPd?±µ???Âj?d?±µ???ªj
?d?±µ?É?Êjdd?±µ?É??jRd?±µ????j?d?±µ?É?Êj$d?±µ???ªjRd?±µ???Âj?d?±µ?Â?ÂjTd?±µ???ªj?d?±µ???Êj?d
?±µ????jRd?±µ????j?d?±µ?É?ÊjTd?±µ???ªjRd?±µ???Âj?d?±µ???Âj?d?±µ?É?ªjRd?±µ???ÊjRd?±µ?Ò??jTd?±
µ????j?d?±µ???Êj
Why?
Edit:
I had set the digital pin 0 to output, and I thought maybe that was the problem so I went to the Arduino website and found the page Analog Input Pins.
So I tried to read from pin 14 which they say is the analog input pin 0, but I got the same output.
By the way, I'm trying to read from the analog only pins, not the one wich are also digital.
Try running this sample code found on the Arduino website. You shouldn't need to convert the variable valm or anything.
/*
Analog input
Reads an analog input on analog in 0, and prints the value out.
Created 24 March 2006
by Tom Igoe
*/
int analogValue = 0; // Variable to hold the analog value.
void setup() {
// open the serial port at 9600 bit/s:
Serial.begin(9600);
}
void loop() {
// Read the analog input on pin 0:
analogValue = analogRead(0);
// Print it out in many formats:
Serial.println(analogValue); // print as an ASCII-encoded decimal
Serial.println(analogValue, DEC); // print as an ASCII-encoded decimal
Serial.println(analogValue, HEX); // print as an ASCII-encoded hexadecimal
Serial.println(analogValue, OCT); // print as an ASCII-encoded octal
Serial.println(analogValue, BIN); // print as an ASCII-encoded binary
Serial.println(analogValue, BYTE); // print as a raw byte value
// Delay 10 milliseconds before the next reading:
delay(10);
}
If your output is still gibberish, there's something wrong with your serial terminal.
The problem Here is analog device you might connected are not # same ground potentials.
Example: If your powering on Arduino board using PC and sensor is powered on using other source , But You trying to read value from Arduino port, for this instant it gives above error. Try this power on arduino and sensor from Same power source and try to read data using Serial Port through DOcklight you will get Problem solved.
You need to set the baud rate in the serial monitor window (bottom right corner) to the same value that has been set in your code (e.g. Serial.begin(9600);).
From what your output looks like, it seems like you need to convert valm into a string, so that you can print the value numerically.
Also, is the wire you plugged into analog in floating? Because if it is, it'll just act like an antenna and grab random noise (though, might have a strong 60Hz component).

Resources