Go Down

Topic: Hardware RNG (prelim library) (Read 383 times) previous topic - next topic


Mar 02, 2018, 10:54 pm Last Edit: Mar 03, 2018, 05:00 pm by robtillaart
Hello all,

I have been working with the Adafruit nRF52 BTLE Feather, and I noticed that it has a cool hardware RNG as well as many other useful registers.  I am not a classically trained programmer so my knowledge is spotty at best when it comes to dealing with deep hardware programming.

I am running into an issue and I've not had great luck figuring out how to troubleshoot it.  The library appears to work great, 99 times.  At the 100th call of the function (every 100th time), it breaks out of the for loop.  I am thinking it may be a strange interrupt case, but I can't figure out why 100?

I'm going to keep on chugging, but it would be great if anyone who understands hardware interrupt timers would be able to just take a peak and see if there are any egregious formatting errors in the .cpp or .h files.

If interested, I will keep the github updated here:



Unrelated to your problem, but I'd like to make a suggestion for your library:
Consider moving the library to the root of the repository, rather than being in the hRNG subfolder. This will allow users to install the library more easily by downloading via GitHub's Clone or Download > Download ZIP, then the Arduino IDE's Sketch > Include Library > Add .ZIP Library. Even for more advanced users who want to git clone the repository to their libraries folder. This repository structure is also required if you want to add the library to the Arduino Library Manager index.


Thank you very much Pert for your insights into some standard formatting that I was unaware of, I have updated the github to reflect those changes, and I have applied your masterful keyword.txt formatting (I was a little confused about that initially).

I believe I have figured out the issue after a couple bouts of maddening debugging, I noticed that in the example sketch, I had to change the for loop to a not as standard:
Code: [Select]
for(z = 1, y = 1; z < pool; z++, y++){

The z=1 was a quick way of using the remainder % operator to make the serial printing look prettier.  The reason it was constantly skipping 100th number, would be because "pool" was set to 100 and the correct for is:
Code: [Select]
for(z = 1, y = 1; z < (pool+1); z++, y++){

or z=pool may be better, either way, the conclusion here is that I am still not a wizard :(

I will continue to develop this into a much larger scope library, and if I write any more example sketches I will make sure to proof read them until my eyes are bleeding before posting!


I have applied your masterful keyword.txt formatting (I was a little confused about that initially).
Actually you only approved the pull request and then closed it. It's still unmerged and so the problematic keywords.txt formatting remains in your repository.

Perhaps you're unfamiliar with how GitHub works? If so, here's a short overview on this topic:

There's requirement to merge it of course, I just thought I should clarify that. Keywords highlighting is of limited use in the Arduino IDE but a lack or inconsistency of highlighting does frequently act as a red herring to beginners "I installed the library but the function isn't orange" so I still think it's worth the effort.


yeap, I have zero idea how github works =0

I just went in and edited the keywords.txt sorry if it doesn't credit your work to you, thanks though!


I don't care at all about credit. The only thing that annoys me is when people do that and don't take a second to leave a comment when they close the pull request, which causes me to waste time trying to figure out why it was rejected. It's also annoying when people don't bother to close the pull request at all because then I have this fork hanging around forever that I could have deleted and a dead pull request on my open PR list.

It also sometimes seems like people do this because they don't want to give anyone else credit. Even though I don't care about the credit for myself, it reminds me of the pettiness of humans, which the open source movement usually helps me to forget. In this case it's clear your actions are driven by lack of familiarity with the system rather than greed.

However, your edit still didn't solve the problem. A true tab separator is required but you used spaces instead of tabs. It's really simple to just click that "Merge" button. If you're going to use GitHub it's worth taking a little time to understand the basics. I think it would have already saved you time and would continue to do so in the years to come.

Go Up