tag:blogger.com,1999:blog-4542176549692404194.post827775539531528337..comments2023-03-18T04:12:28.727-05:00Comments on Projects from Tech: Serial Communication on a ATtiny85 with the SoftwareSerial Library.Matthewhttp://www.blogger.com/profile/07493487402447428879noreply@blogger.comBlogger29125tag:blogger.com,1999:blog-4542176549692404194.post-38037617719702798422015-02-24T07:35:08.745-06:002015-02-24T07:35:08.745-06:00I had similar problem when I tested my HC-06 and f...I had similar problem when I tested my HC-06 and found out, it was on 5V... When I connected it to 3.3V, it was working correctly, hope it helpslessthanmorenoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-72740904960948250542014-09-18T09:25:48.018-05:002014-09-18T09:25:48.018-05:00Thanks for you kind comments Mathew. I have tried ...Thanks for you kind comments Mathew. I have tried the Arduino serial monitor too, but I got the similar results. Later on, I have tried the ATtiny85 and now the LED is blinking, but the messages coming from ATTiny are received at the serial monitor as either 0, 80 or 128 in Hex (meaningless characters like €€ or <0> in ASCII). Moreover, the LED always blinks to the maximum value, whatever number I send from the serial monitor. This means that, the number I send is not recognized correctly by the ATTiny85 either. Do you think there is an encoding problem, or what else?Suha Bayindirnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-3121218205429931312014-09-17T07:39:23.881-05:002014-09-17T07:39:23.881-05:00Well if your baud rates are the same on both the t...Well if your baud rates are the same on both the the ATtiny and the serial monitor I would reflash the ATtiny. Make sure it is at 8MHz. You might try just using the Arduino serial monitor too. I haven't used Putty much but I suppose it might have some different settings turned on.Matthewnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-44600376896981293352014-09-14T16:19:43.809-05:002014-09-14T16:19:43.809-05:00Hi Mathew, Thanks for your valuable guidance. I ha...Hi Mathew, Thanks for your valuable guidance. I have tried your instructions on ATTiny45. Everything was OK during programming stages and the HC06 bluetooth paired with the laptop bluetooth succesfuly. However, the comments sent by the ATTiny45 were received as a continuous stream of unrecognized characters on the Putty serial monitor and the LED does not blink either. The baud rate was 9600 which I had used before while communicating arduino uno with HC06 succesfuly. Is the problem related to ATTiny 45 or what else may be the reason for these unexpected characters? I would be very pleased if you could guide me to sort out this problem.Suha Bayindirnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-43830103716471971262014-07-17T05:10:50.844-05:002014-07-17T05:10:50.844-05:00@William turner
I had the same. Use Arduino Softwa...@William turner<br />I had the same. Use Arduino SoftwareSerial also on your Arduino Uno. http://arduino.cc/en/Tutorial/SoftwareSerialExample<br /><br />When I connect to the harware serial I got 'yyyyyyy', when connecting to software pins it's working!!!Johan Hoeksmanoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-53869934642353174442014-05-14T13:16:36.384-05:002014-05-14T13:16:36.384-05:00The fixed example source is listed above in my pos...The fixed example source is listed above in my post, just use it as is. I don't recommend changing the core files.Wild Westnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-84963580709891632272014-05-14T12:38:47.555-05:002014-05-14T12:38:47.555-05:00Please tell us how did you fix it! I found the tin...Please tell us how did you fix it! I found the tiny core folder but I'm not sure what should I add there.Tregnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-54774891215662141462014-05-06T18:42:33.583-05:002014-05-06T18:42:33.583-05:00I just tried it with fuses for ATtiny85 @ 16 MHz ...I just tried it with fuses for ATtiny85 @ 16 MHz (internal PLL; 4.3 V BOD) and it works fine there also. Thanks Mathew, I would probably still be using the "poor man's display" if I hadn't found this page. :-)Wild Westnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-78776026871456491802014-05-06T18:26:32.303-05:002014-05-06T18:26:32.303-05:00Tested and it works. I used ArduinoISP on my UNO t...Tested and it works. I used ArduinoISP on my UNO to program the Tiny85 and then a PL2303 usb cable for the serial connection which I connected to with the serial port terminal program GtkTerm on Linux.<br /><br /> /* <br /><br /> Software serial multple serial test <br /><br /> Receives an integer from the software serial, blinks an LED that number of times, and returns a confirmation. <br /><br /> The circuit: <br /><br /> * RX is digital pin 10 (connect to TX of other device) <br /><br /> * TX is digital pin 11 (connect to RX of other device) <br /><br /> Note: <br /><br /> Not all pins on the Mega and Mega 2560 support change interrupts, <br /><br /> so only the following can be used for RX: <br /><br /> 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 <br /><br /> Not all pins on the Leonardo support change interrupts, <br /><br /> so only the following can be used for RX: <br /><br /> 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). <br /><br /> This code has been modified for use on an ATtiny. <br /><br /> Created by Matthew on June 11, 2013 <br /><br /> http://projectsfromtech.blogspot.com/ <br /><br /> This example code is in the public domain. <br /><br /> */ <br /><br /> #include <SoftwareSerial.h> <br /><br /> SoftwareSerial TinySerial(3, 4); // RX, TX <br /><br /> //------------------------------------------------------------------- <br /><br /> /* <br /><br /> The tiny core doesn't support SoftwareSerial.parseInt() <br /><br /> so these methods are copied from the arduino 1.0.5 core <br /><br /> Stream.cpp with very minor modifications so they will work <br /><br /> outside the class as stand alone subroutines. <br /><br /> */ <br /><br /> unsigned long startMillis; // used for timeout measurement <br /><br /> int timedPeek(){ <br /><br /> int c; <br /><br /> startMillis = millis(); <br /><br /> do { <br /><br /> c = TinySerial.peek(); <br /><br /> if (c >= 0) return c; <br /><br /> } <br /><br /> while(millis() - startMillis < 1000); <br /><br /> return -1; // -1 indicates timeout <br /><br /> } <br /><br /> int peekNextDigit(){ <br /><br /> int c; <br /><br /> while (1) { <br /><br /> c = timedPeek(); <br /><br /> if (c < 0) return c; // timeout <br /><br /> if (c == '-') return c; <br /><br /> if (c >= '0' && c <= '9') return c; <br /><br /> TinySerial.read(); // discard non-numeric <br /><br /> } <br /><br /> } <br /><br /> long parseInt(void){ <br /><br /> boolean isNegative = false; <br /><br /> long value = 0; <br /><br /> int c; <br /><br /> c = peekNextDigit(); <br /><br /> // ignore non numeric leading characters <br /><br /> if(c < 0) <br /><br /> return 0; // zero returned if timeout <br /><br /> do{ <br /><br /> if(c == '-') <br /><br /> isNegative = true; <br /><br /> else if(c >= '0' && c <= '9') // is c a digit? <br /><br /> value = value * 10 + c - '0'; <br /><br /> TinySerial.read(); // consume the character we got with peek <br /><br /> c = timedPeek(); <br /><br /> } <br /><br /> while(c >= '0' && c <= '9'); <br /><br /> if(isNegative) <br /><br /> value = -value; <br /><br /> return value; <br /><br /> } <br /><br /> //------------------------------------------------------------------- <br /><br /> void setup() <br /><br /> { <br /><br /> // Open serial communications and let us know we are connected <br /><br /> TinySerial.begin(9600); <br /><br /> TinySerial.println("Tiny Serial Connected via SoftwareSerial Library"); <br /><br /> pinMode(1, OUTPUT); <br /><br /> } <br /><br /> void loop() <br /><br /> { <br /><br /> if(TinySerial.available()) <br /><br /> { <br /><br /> int received = parseInt(); // get an integer from serial input <br /><br /> TinySerial.print("Received data..."); <br /><br /> TinySerial.println("Flashing LED"); <br /><br /> if(received >=30) //So it doesn't blink 150 times when you type 150 instead of 15 <br /><br /> received = 30; <br /><br /> Blink(1, received); //Blink the LED on pin 1 <br /><br /> } <br /><br /> } <br /><br /> void Blink(byte led, byte times){ // poor man's display <br /><br /> for (byte i=0; i< times; i++){ <br /><br /> digitalWrite(led,HIGH); <br /><br /> delay (250); <br /><br /> digitalWrite(led,LOW); <br /><br /> delay (175); <br /><br /> } <br /><br /> }Wild Westnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-90842232716154890792014-05-06T12:43:12.190-05:002014-05-06T12:43:12.190-05:00When I look at Stream.cpp in the tiny core the par...When I look at Stream.cpp in the tiny core the parseInt() and other parse functions are not present. My guess is this was done to keep the image size small for the tiny chips. So it is a mystery how it could work for anyone using the tiny core because the code is simply not there. With that said, the easiest approach is to copy the class methods necessary to support parseInt() from the 1.0.5 core and fix them to compile as stand alone functions. It adds about 50 lines of code to the example and it compiles good but I will not be able to test it on my tiny85 until later this evening.Wild Westnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-6656719335874941122014-05-06T09:13:00.356-05:002014-05-06T09:13:00.356-05:00Well I didn't change it originally because I d...Well I didn't change it originally because I didn't know any better. Unfortunately for the reader this blog has to follow my own learning path. I didn't realize it was a widespread problem. <br /><br />I changed it a bit so that it doesn't use parseInt(). I don't have time to test it right now, but I will post it so you can try it. Let me know if it works (or doesn't).<br /><br />https://drive.google.com/file/d/0B6s_UhmkBLQfa0Nwc3hwUHpwZjQ/edit?usp=sharingMatthewnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-70001000876078959072014-05-06T01:09:25.204-05:002014-05-06T01:09:25.204-05:00I also get the error ‘class SoftwareSerial’ has no...I also get the error ‘class SoftwareSerial’ has no member named ‘parseInt’ with 1.0.5. Looked around the internet and tried a few things but no luck. Why don't you change your example program so it doesn't use parseInt()? It would be so nice if your download just worked for everyone.Wild Westnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-44411740839773226532014-04-13T20:21:03.027-05:002014-04-13T20:21:03.027-05:00So that didn't fix the problem. Well it could ...So that didn't fix the problem. Well it could be that I actually used the high-low tech ATtiny core for this post. It's hard for me to keep up with it, but I don't think I used that one for very long. I would just suggest you triple check that you are running at 8MHz and have everything installed correctly. If you find a solution, let us know though.<br /><br /><br />If it turns out to be really bothersome, I might just go with a serial.read and combine them myself.Matthewnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-89845703913071360662014-04-12T10:51:06.590-05:002014-04-12T10:51:06.590-05:00On a fresh 1.0.5 install with the core from the li...On a fresh 1.0.5 install with the core from the link provided (https://code.google.com/p/arduino-tiny/), I also get the ParseInt-error.. the person with the same problem on the arduino forum got his problem fixed, but didn't care to share the actual solution..renénoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-29802623118889969392014-01-11T10:53:55.629-06:002014-01-11T10:53:55.629-06:00Ok. Well from your example the ATtiny would be lik...Ok. Well from your example the ATtiny would be like the atmega328 in an Arduino. I think it is the "minimum system" you are looking for. If you want to run it at 8MHz, you don't need a crystal. Just connect it to 5V and Ground (assuming the fuses are set correctly). <br /><br /><br />That is all you really need. A decoupling capacitor might be nice if you are using a messy power supply. You might look at my ATtiny label if you want more information on using an ATtiny with the Arduino IDE.Matthewnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-36838530364347227632014-01-09T19:53:51.121-06:002014-01-09T19:53:51.121-06:00yes "minimum system" , the minimum syste...yes "minimum system" , the minimum system to use attiny85.<br />something like arduino uno (minimum system of atmega328), there is some component like crystal, capasitor, resistor, etcEdward Hiskianoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-15133728852472405872014-01-09T11:10:32.304-06:002014-01-09T11:10:32.304-06:00I'm not sure I understand your question. Can y...I'm not sure I understand your question. Can you please rephrase it?Matthewnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-42156222561488745212014-01-09T03:21:00.061-06:002014-01-09T03:21:00.061-06:00is attiny85 have minimum system ?is attiny85 have minimum system ?Edward Hiskianoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-90810368988961010082013-09-29T17:36:51.816-05:002013-09-29T17:36:51.816-05:00Yes that was a typo. Projects running together. I ...Yes that was a typo. Projects running together. I updated the post. <br />Thanks for pointing that out.Matthewnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-3922701700072214892013-09-28T18:44:37.681-05:002013-09-28T18:44:37.681-05:00Does this require the Software SERVO library or is...Does this require the Software SERVO library or is that a typo and you mean Software Serial?tz1noreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-67305101293086721332013-09-12T12:25:50.109-05:002013-09-12T12:25:50.109-05:00Yes that is possible. See the pinout chart above. ...Yes that is possible. See the pinout chart above. As far as I know, any of the IO pins can be used with SoftwareSerial. Then you can use whichever ones you don't need for other things. If you need serial and more than 3 IO pins, you could also use the reset pin as an IO. http://projectsfromtech.blogspot.com/2013/04/using-reset-pin-as-io-on-attiny8545.html<br /><br /><br />Hope that helpsMatthewnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-85469812932610970022013-09-11T11:36:52.736-05:002013-09-11T11:36:52.736-05:00Hi Mathew.
I just found your writeup.
If I need se...Hi Mathew.<br />I just found your writeup.<br />If I need serial communication and also need 2x digital (or analog) inputs, is it possible using this Attiny45 ?<br />If so, which pins I can use as inputs ?<br /><br />Sincerely<br />-bino-Bino Oetomonoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-68872932098913645612013-09-07T16:28:10.373-05:002013-09-07T16:28:10.373-05:00I'm not sure what the problem is. It compiles ...I'm not sure what the problem is. It compiles just fine for me on both 1.0.3 and 1.0.5. No chance the library has been changed or something, right? I am no expert, but the way I understand it SoftwareSerial inherits parseInt from Stream.h. Does parseInt work with your regular Serial library?<br /><br /><br />Before you dig too much into that I would download a fresh copy of 1.0.5 and drop in a fresh copy of the ATtiny core from Google code.<br /><br /><br />if all that fails, you could do a simple read() and then combine them into an int in code. I know there are various methods of doing that online.Matthewnoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-71273408973875045922013-09-06T18:54:14.056-05:002013-09-06T18:54:14.056-05:00I'm having the same problem. Using IDE version...I'm having the same problem. Using IDE versions 1.0.3 and 1.0.5, and I would try the beta version 1.5.2 except that I can't figure out how to get the ATtiny chips to show up in that version. They show in the stable releases though, so that's not my problem. I'm also using the example code SoftwareSerialBlink.ino that I downloaded from this page.<br /><br />It's the same parseInt problem that Tom is/was having. <br /><br />Also thank you very much for writing up this how to and example code, I'm really looking forward to getting it working!!Jesseynoreply@blogger.comtag:blogger.com,1999:blog-4542176549692404194.post-13771367606182525702013-08-29T09:01:40.001-05:002013-08-29T09:01:40.001-05:00Hi Tom,
Check out this link http://forum.arduino...Hi Tom, <br /><br />Check out this link http://forum.arduino.cc/index.php?topic=185122.0<br /><br />You may just need a different core. Try this one https://code.google.com/p/arduino-tiny/<br /><br /><br /><br />Also, make sure you have a recent IDE version. <br /><br /><br />Is this one of the examples? If not, check for typos and make sure your include is right. If you could, comment back with the results whatever they are. It helps to see and document what kind of problems people may encounterMatthewnoreply@blogger.com