Can I use stepper motor and crystal oscillator with attiny85

Hello, I want to make a system that will rotate a few steps every hour using Attiny85 and 28byj-48 stepper motor. However, attiny85's own timer slips by a few seconds every hour. Since I want the system to work regularly for 7 days, I want to use 8mhz crystal. I need a time difference of less than 15 minutes for a period of 7 days.

Stepper small_stepper(STEPS, 0, 2, 1, 3);
I can drive the stepper motor successfully using the code, but when I leave pins 2 and 3 empty and use pins 4 and 5 instead to connect the osulator, the system does not work. Frankly, I am not a very experienced user, and I was not sure how to make the necessary settings when I connected an external oscillator. I use Arduino IDE and USB for programming. I also have an Ardiuno Nano that I can use as an ISP.

As attiny85, I use a built-in USB digispark card.

Which core are you using?

I prefer the ATTinyCore core. It makes it easy to choose the options that you want.

I just looked and the ATTinyCore has no option for 8MHz external oscillator when Digispark is chosen.

I don't know if you can use an external crystal with Digispark. I have used external crystal with a tiny85 for a clock project and it was very accurate.

You may try to set a more accurate internal frequency of the ATTiny85 via the OSCCAL register. There's nothing stopping you from trying.

Page 31 6.5.1 OSCCAL – Oscillator Calibration Register

Page 194 Figure 22-42. Calibrated 8 MHz RC Oscillator Frequency vs. OSCCAL Value

When choosing the board, I choose "attinycore>ATTiny85(micronucleus/digispark)" via the Arduino ide. My other settings: "Clock:16.5mhz, tuned of usb (usb)", "timer1 clock: cpu", "LTO:Enabled", "reset pin ( only set on bootload via ISP): reset", "BOB level: disabled", "Burn bootloader method: Uprage (via usb)".

I don't fully understand whether changing the number in the code below is sufficient for oscal calibration.

void setup() {
OSCCAL += 3;
}

Also, will it provide a more stable timing if I run the device at 1mhz instead of 16.5 mhz?

I plan to run the device with a 3.7v battery, but for now I'm working with 5v usb. In addition, when the device will be used outdoors, there may be temperature changes between -20 and +40 degrees depending on the season. Would it be a major problem for your own rc osulator? As I mentioned before, up to 15 minutes of error in 7 days is acceptable.

I have one last question, can I upload the codes at once after setting it as "reset pin (only set on bootload via ISP): GPIO(danger- disabled ISP" in the Arduino ide.

No, the existing 8MHz clock is simply divided by 8, so the error remains.

The proper way to adjust the internal clock timing is to adjust the OSCCAL register, up or down as required. If you have a stable timing source for digital comparison, a program can make the adjustment automatically. Otherwise, use trial and error.

Very large temperature range. According to the ATTiny85 data, perhaps the accuracy will not be sufficient. Also, are you sure this motor will work at such a different temperature?

1 Like

Use a ds3231 RTC, available on a breakout board. Has internal 32768 Hz crystal with temperature compensation very easy to use
https://www.amazon.co.uk/AZDelivery-DS3231-Real-Clock-Parent/dp/B07ZQKGTBK.

2 Likes

The internal oscillator will vary by temperature and battery voltage (assuming you run the chip directly from the li-ion/li-po battery), so no value of OSCCAL will work in all conditions.

I would suggest using a ds3231 RTC module. These have very accurate, temperature compensated, internal crystals.

Next best would be to attach a 32KHz crystal to the attiny, I think. 2x caps would also be needed.

I'm not sure digispark is best choice. It runs at 5V and may not run correctly at lower voltages as your battery gets low. A bare attiny85/84 would be my choice

1 Like

From what I've read, the stepper motor should be working between -20 and 70 degrees. As far as I understand, realizing this project with attiny85 seems to be beyond me at the moment. I have an Arduino pro mini 3.3v development board. Since there is an external osulator on the board, can I get more reliable timing in this case? Do I need to connect DS3231 RTC to this card again? Since my working area is limited, I try to use the least number of components. -One of the ways I used Attin85 was to design my own PCB board-. https://www.amazon.com/CWUU-Rechargeable-Battery-9900mAh-Flashlight/dp/B0CG1KL3RC/?th=1
If I feed my Arduino Pro mini (3.3v version) board and stepper motor with a battery like this, can the system work for a week?

The operation of the system is as follows: The stepper motor rotates approximately 2 degrees every hour, then saves the data on all pins to variables and cuts the current to the motor by turning all the values low. It waits for 1 hour until the next turn and then turns 2 more degrees from the last remaining position based on the data it recorded. (I couldn't explain this part clearly because my English is bad, but the system works).

Again, can I use the method specified here to spend less energy during the waiting period? Mega328P - Power saving and the watchdog timer over an extended time period

You posted the wrong link, it is not the link for the board you designed. The link is for some fake/scam 18650 batteries. No 18650 battery has a capacity of 9900mAh.

When I search on shopping sites, there are batteries stated to have very different capacities among 3.7v batteries. As you said, some of these may be misleading, but if we consider an average 3.7 volt battery, can I use the ardionu pro mini (3.3v) and 28byj-48 stepper motor (and maybe DS3231 RTC) for a week? Please keep in mind that the stepper motor will only rotate once a week and consume electricity only while rotating.
I have basic knowledge of electronics and Ardiuno, but I am not an expert. Maybe he's asking very simple questions. Thank you very much everyone for all the answers

Check the operating temperature range of the batteries, you may be unpleasantly surprised.

Frankly, this is what I'm afraid of the most. But I think it's worth a try

For long term operation over wide temperature range I recall that the best battery type is lithium thionyl chloride but these are non rechargeable. Used for example in utility meters.

I used Everready lithium cells for a deer feeder. Just to power the electronics. I used gel cell 12 volt to power the motor. Regular alkaline cells did not like the -20F and lower temperatures. The PIC micro running at 32khz just sipped power. The cells lasted over 2 years.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.