Author Topic: Serial - Why Does This Work?  (Read 11307 times)

Dragon

  • Newbie
  • *
  • Posts: 19
Serial - Why Does This Work?
« on: April 22, 2013, 07:30:05 pm »
Hello all.


I recently got the JY-MCU Bluetooth chip for my Digispark.
I hooked it up, using pin two on the Digispark to transmit to the Bluetooth and set up my desktop to recieve and print the values coming over the Bluetooth adapter.


Then I set up the code using the SoftSerial examples that I've seen on the forums and in the DigisparkSoftSerial example in the Arduino folder.
After playing around for a bit, I realized something: I don't need SoftSerial to use serial communication with Bluetooth. Only when on pin two, I am able to just use the Serial.write() function.


The reason for my confusion is that I thought that, because of the Digispark's form factor, it was limited in functionality, meaning no on board Serial, meaning we had to use software serial.
However, I am seeing that I am able to fully use Serial for writing and I receive and see the correct value on the other side, when on pin 2. I have not yet tried reading, so I can not comment to that.


So, what's going on here?


Here is the entirety of my code:
Code: [Select]
int i = 0;
void setup() 
{
  Serial.begin(9600);
}
void loop()
{
  Serial.write(i);
  i++;
  delay(125);   
}
« Last Edit: April 22, 2013, 07:45:20 pm by Dragon »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Serial - Why Does This Work?
« Reply #1 on: April 22, 2013, 09:02:04 pm »
There is some software serial built into the core - it hasn't been tested as much as SoftSerial - but it is there and that's why Serial works - it's not hardware nor does it send data back over USB. Glad it worked for you!

Dragon

  • Newbie
  • *
  • Posts: 19
Re: Serial - Why Does This Work?
« Reply #2 on: April 22, 2013, 11:12:46 pm »
There is some software serial built into the core
Neat!


Can you comment on reading values via Serial (i.e. what pin it might be on)?
I haven't had the chance to experiment with that yet.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Serial - Why Does This Work?
« Reply #3 on: April 23, 2013, 01:43:10 am »
Sorry I should have mentioned - the other limitation is that it is one way (TX) only - it was written for debugging (part of the original Tiny Core, not written by us)

Dragon

  • Newbie
  • *
  • Posts: 19
Re: Serial - Why Does This Work?
« Reply #4 on: April 23, 2013, 12:47:46 pm »
Sorry I should have mentioned - the other limitation is that it is one way (TX) only - it was written for debugging (part of the original Tiny Core, not written by us)
Ah, I see.
Well it's still a great tool for passive sensor devices that only need to transmit :D

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Serial - Why Does This Work?
« Reply #5 on: April 23, 2013, 06:08:38 pm »
Maybe it should be changed with some #define magic to just use SoftSerial with some default pins?

Dragon

  • Newbie
  • *
  • Posts: 19
Re: Serial - Why Does This Work?
« Reply #6 on: April 23, 2013, 10:31:13 pm »
Quick question for Digistump: can you point me to documentation that outlines this feature of the Tiny?
I'd like to learn more about it's limitations. Atmel's doc doesn't seem to mention anything about it.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Serial - Why Does This Work?
« Reply #7 on: April 24, 2013, 02:21:44 am »
Here is the original tiny-core page: https://code.google.com/p/arduino-tiny/


Digispark uses a slightly modified but functionally the same version - I don't think there are any "Docs" on it - but lots of people use it with Attinys and there are a far number of answers to common questions about it on the Arduino forum. Mostly it tries to be the same as the standard Arduino core, only for the attiny - of course hardware limits it from doing everything (like hardware serial).




If you look at the source - the serial comes from the TinyDebugSerial files.


barbudor

  • Newbie
  • *
  • Posts: 9
Re: Serial - Why Does This Work?
« Reply #8 on: November 06, 2013, 12:30:41 pm »
Dear Digistump

The arduino-tiny that you have included in your Arduino IDE distribution is now a few months old.
It would be nice if you could merge you changes with the official GIT tree or at least make a proper branch in GIT so we can do this merge.

I think it is a pity that 2 separate branch of this nice environment lives separately.

Would you be kindly contact the original author to work on this ?

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Serial - Why Does This Work?
« Reply #9 on: November 06, 2013, 02:00:46 pm »
The digispark core contains digispark-specific code which interacts with the bootloader, particularly in relation to clock speed selection and support for 16.5mhz, as well as changes to how interrupts are handled which are a different compromise that only makes sense in the context of emulating USB. I don't think they should be merged, but it would be good for digispark core to import improvements in the tinycore.

The core is already on github at https://github.com/digistump/DigisparkArduinoIntegration/tree/master/hardware/digispark

Also.. um.. what the heck is going on with their repo? https://code.google.com/p/arduino-tiny/source/list they say they 'initially published' in may of this year, and have only made one commit since then. What's the point?
« Last Edit: November 06, 2013, 02:05:03 pm by Bluebie »

barbudor

  • Newbie
  • *
  • Posts: 9
Re: Serial - Why Does This Work?
« Reply #10 on: November 07, 2013, 12:35:54 pm »
Hi Bluebie

Thank you for your answer.

First I was totally out of my shoes as arduino-tiny is on code.google and not on github, so no real forking can occur between the 2 sites   :-X
With regards to the date, I think he restarted a new repo on May 24th because I have found on my HDD versions older that this date. I think they were pre-1.0 and he restarted from the beginning on May 24 with v1.0.

I am not sure to understand why it could not be merged (apart from being on different sites) but I trust you.
I started to made some diff between the "arduino-tiny" distro I am using and digispark's one and mainly saw #if related to F_CPU=16500000.

But beside this I also found more in deep changes such as the delayMicroseconds() function that you seem to have totally rewritten.
So I was wondering : now I have found 2 tiny cores which are note the same, which one should I use ?
And if I try myself to merge them, in addition to probably making mistake that would have created a 3rd branch .....

It was probably a stupid dream  ;D that one could fit all and we could have advantages of both in a single core (while I am unable to point which advantages each one could have outside of USB support of course).

Thanks for all

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Serial - Why Does This Work?
« Reply #11 on: November 07, 2013, 06:06:25 pm »
If you want to create arduino programs on the digispark, definitely use the digispark core. If you want to use digispark usb libraries, also use digispark core. If you're using the micronucleus bootloader, I think digispark core is better. If you're making low speed devices which wont do any USB, you might have a nicer time using tinycore. Your programs are likely to compile to be slightly smaller with tinycore as they omit digispark-specific setup code.

barbudor

  • Newbie
  • *
  • Posts: 9
Re: Serial - Why Does This Work?
« Reply #12 on: November 07, 2013, 10:31:57 pm »
Thanks a lot
Best regards